Goby v2
logger_manipulators.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef LoggerManipulators20091110H
24 #define LoggerManipulators20091110H
25 
26 #include <iostream>
27 #include <string>
28 
29 #include "term_color.h"
30 
31 namespace goby
32 {
33 namespace common
34 {
35 class FlexOstream;
36 
37 namespace logger
38 {
40 inline std::ostream& die(std::ostream& os)
41 {
42  return (os << goby::common::tcolor::red << "(Error): " << goby::common::tcolor::nocolor);
43 }
44 
46 inline std::ostream& warn(std::ostream& os)
47 {
48  return (os << goby::common::tcolor::red << "(Warning): " << goby::common::tcolor::nocolor);
49 }
50 
52 inline std::ostream& verbose(std::ostream& os) { return (os); }
53 
55 inline std::ostream& debug1(std::ostream& os) { return (os << "D: "); }
56 
58 inline std::ostream& debug2(std::ostream& os) { return (os << "D2: "); }
59 
61 inline std::ostream& debug3(std::ostream& os) { return (os << "D3: "); }
62 
63 } // namespace logger
64 } // namespace common
65 } // namespace goby
66 
68 class Group
69 {
70  public:
71  Group(const std::string& name = "", const std::string& description = "",
72  goby::common::Colors::Color color = goby::common::Colors::nocolor)
73  : name_(name), description_(description), color_(color), enabled_(true)
74  {
75  }
76 
78 
79  std::string name() const { return name_; }
82  std::string description() const { return description_; }
84  goby::common::Colors::Color color() const { return color_; }
86  bool enabled() const { return enabled_; }
88 
90 
91  void name(const std::string& s) { name_ = s; }
92  void description(const std::string& s) { description_ = s; }
93  void color(goby::common::Colors::Color c) { color_ = c; }
94  void enabled(bool b) { enabled_ = b; }
96 
97  private:
98  std::string name_;
99  std::string description_;
101  bool enabled_;
102 };
103 
104 std::ostream& operator<<(std::ostream& os, const Group& g);
105 
108 {
109  public:
110  explicit GroupSetter(const std::string& s) : group_(s) {}
111  void operator()(std::ostream& os) const;
112  void operator()(goby::common::FlexOstream& os) const;
113 
114  private:
115  std::string group_;
116 };
117 
118 inline GroupSetter group(std::string n) { return (GroupSetter(n)); }
119 
120 inline std::ostream& operator<<(std::ostream& os, const GroupSetter& gs)
121 {
122  gs(os);
123  return (os);
124 }
125 
127 
129 std::ostream& basic_log_header(std::ostream& os, const std::string& group_name);
130 
131 #endif
Helper class for enabling the group(std::string) manipulator.
Forms the basis of the Goby logger: std::ostream derived class for holding the FlexOStreamBuf.
Definition: flex_ostream.h:43
bool enabled() const
Is this group enabled?
Color
The eight terminal colors (and bold or "light" variants)
Definition: term_color.h:111
std::ostream & operator<<(std::ostream &out, const google::protobuf::Message &msg)
provides stream output operator for Google Protocol Buffers Message
Definition: core_helpers.h:49
std::ostream & red(std::ostream &os)
All text following this manipulator is red. (e.g. std::cout << red << "text";)
Definition: term_color.h:62
goby::common::Colors::Color color() const
Color to use when displaying this group (for streams that support terminal escape codes only: std::co...
The global namespace for the Goby project.
std::string description() const
Human readable description of this group.
std::ostream & nocolor(std::ostream &os)
All text following this manipulator is uncolored (e.g. std::cout << green << "green" << nocolor << "u...
Definition: term_color.h:104
Defines a group of messages to be sent to the Goby logger. For Verbosity == verbose streams...