22 #include "goby/common/logger.h" 30 inline std::ostream& stream_assert(std::ostream& os) { assert(
false); }
42 std::ostream&
operator<<(std::ostream& out,
const A& a) {
return out << a.i; }
44 void spew(
int n,
int m,
int run)
49 glog.is(VERBOSE) &&
glog <<
"Spew 1: " << std::endl;
50 for (
int i = 0; i < n; i++)
glog.is(VERBOSE) &&
glog << m <<
" " << i << std::endl;
54 glog.is(VERBOSE) &&
glog <<
"Spew 2: " << std::endl;
55 for (
int i = 0; i < n; i++)
glog.is(VERBOSE) &&
glog << m <<
" " <<
A(i) << std::endl;
59 glog.is(VERBOSE) &&
glog <<
"Spew 3: " << std::endl;
60 for (
int i = 0; i < n; i++)
glog << m <<
" " << i << std::endl;
64 glog.is(VERBOSE) &&
glog <<
"Spew 4: " << std::endl;
65 for (
int i = 0; i < n; i++)
glog << m <<
" " << i;
70 glog.is(VERBOSE) &&
glog <<
"Spew 5: " << std::endl;
71 for (
int i = 0; i < n; i++)
72 glog.is(VERBOSE) &&
glog << m <<
" " << i << std::endl << i << std::endl;
81 std::cout <<
"attaching std::cout to QUIET" << std::endl;
83 glog.is(DEBUG3) &&
glog << stream_assert << std::endl;
84 glog.is(DEBUG2) &&
glog << stream_assert << std::endl;
85 glog.is(DEBUG1) &&
glog << stream_assert << std::endl;
86 glog.is(VERBOSE) &&
glog << stream_assert << std::endl;
87 glog.is(WARN) &&
glog << stream_assert << std::endl;
89 std::cout <<
"attaching std::cout to WARN" << std::endl;
91 glog.is(DEBUG3) &&
glog << stream_assert << std::endl;
92 glog.is(DEBUG2) &&
glog << stream_assert << std::endl;
93 glog.is(DEBUG1) &&
glog << stream_assert << std::endl;
94 glog.is(VERBOSE) &&
glog << stream_assert << std::endl;
95 glog.is(WARN) &&
glog <<
"warn ok" << std::endl;
97 std::cout <<
"attaching std::cout to VERBOSE" << std::endl;
99 glog.is(DEBUG3) &&
glog << stream_assert << std::endl;
100 glog.is(DEBUG2) &&
glog << stream_assert << std::endl;
101 glog.is(DEBUG1) &&
glog << stream_assert << std::endl;
102 glog.is(VERBOSE) &&
glog <<
"verbose ok" << std::endl;
103 glog.is(WARN) &&
glog <<
"warn ok" << std::endl;
105 std::cout <<
"checking locking ... " << std::endl;
106 glog.set_lock_action(goby::common::logger_lock::lock);
107 glog.is(VERBOSE) &&
glog <<
"lock ok" << std::endl;
108 glog.is(VERBOSE) &&
glog <<
"unlock ok" << std::endl;
117 glog.is(DEBUG3) &&
glog << stream_assert << std::endl;
119 for (
int i = 0; i < 2; ++i)
121 boost::thread t1(boost::bind(spew, 1000, 1, i));
122 boost::thread t2(boost::bind(spew, 1000, 2, i));
127 glog.set_lock_action(goby::common::logger_lock::none);
129 std::cout <<
"attaching std::cout to DEBUG1" << std::endl;
131 glog.is(DEBUG3) &&
glog << stream_assert << std::endl;
132 glog.is(DEBUG2) &&
glog << stream_assert << std::endl;
133 glog.is(DEBUG1) &&
glog <<
"debug1 ok" << std::endl;
134 glog.is(VERBOSE) &&
glog <<
"verbose ok" << std::endl;
135 glog.is(WARN) &&
glog <<
"warn ok" << std::endl;
137 std::cout <<
"attaching std::cout to DEBUG2" << std::endl;
139 glog.is(DEBUG3) &&
glog << stream_assert << std::endl;
140 glog.is(DEBUG2) &&
glog <<
"debug2 ok" << std::endl;
141 glog.is(DEBUG1) &&
glog <<
"debug1 ok" << std::endl;
142 glog.is(VERBOSE) &&
glog <<
"verbose ok" << std::endl;
143 glog.is(WARN) &&
glog <<
"warn ok" << std::endl;
145 std::cout <<
"attaching std::cout to DEBUG3" << std::endl;
147 glog.is(DEBUG3) &&
glog <<
"debug3 ok" << std::endl;
148 glog.is(DEBUG2) &&
glog <<
"debug2 ok" << std::endl;
149 glog.is(DEBUG1) &&
glog <<
"debug1 ok" << std::endl;
150 glog.is(VERBOSE) &&
glog <<
"verbose ok" << std::endl;
151 glog.is(WARN) &&
glog <<
"warn ok" << std::endl;
153 std::stringstream ss1;
154 std::cout <<
"attaching stringstream to VERBOSE" << std::endl;
156 glog.is(DEBUG3) &&
glog <<
"debug3 ok" << std::endl;
157 glog.is(DEBUG2) &&
glog <<
"debug2 ok" << std::endl;
158 glog.is(DEBUG1) &&
glog <<
"debug1 ok" << std::endl;
159 glog.is(VERBOSE) &&
glog <<
"verbose ok" << std::endl;
160 glog.is(WARN) &&
glog <<
"warn ok" << std::endl;
162 std::cout <<
"ss1: \n" << ss1.rdbuf();
164 glog.
add_group(
"test1", goby::common::Colors::lt_green,
"Test 1");
165 glog.
add_group(
"test2", goby::common::Colors::lt_green,
"Test 2");
167 glog << group(
"test1") <<
"test1 group ok" << std::endl;
168 glog.is(WARN) &&
glog << group(
"test2") <<
"test2 group warning ok" << std::endl;
170 std::cout <<
"All tests passed." << std::endl;
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
int run(int argc, char *argv[], Config *cfg)
Run a Goby application derived from MinimalApplicationBase. blocks caller until MinimalApplicationBas...
void add_group(const std::string &name, Colors::Color color=Colors::nocolor, const std::string &description="")
Add another group to the logger. A group provides related manipulator for categorizing log messages...
std::ostream & operator<<(std::ostream &out, const google::protobuf::Message &msg)
provides stream output operator for Google Protocol Buffers Message
common::FlexOstream glog
Access the Goby logger through this object.
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=0)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity...