23 #ifndef FlexOstream20091211H 24 #define FlexOstream20091211H 30 #include <google/protobuf/io/tokenizer.h> 31 #include <google/protobuf/text_format.h> 33 #include <boost/static_assert.hpp> 35 #include "goby/common/logger/flex_ostreambuf.h" 36 #include "logger_manipulators.h" 46 FlexOstream() : std::ostream(&sb_), sb_(
this), lock_action_(logger_lock::none)
51 std::cerr <<
"Fatal error: cannot create more than one instance of FlexOstream. Use " 52 "global object goby::glog to access the Goby Logger. Do not instantiate " 53 "the FlexOstream directly." 64 const std::string& description =
"");
69 boost::recursive_mutex::scoped_lock l(goby::common::logger::mutex);
75 boost::recursive_mutex::scoped_lock l(goby::common::logger::mutex);
79 bool is(goby::common::logger::Verbosity verbosity);
96 void add_stream(logger::Verbosity verbosity = logger::VERBOSE, std::ostream* os = 0)
98 boost::recursive_mutex::scoped_lock l(goby::common::logger::mutex);
102 void add_stream(goby::common::protobuf::GLogConfig::Verbosity verbosity =
103 goby::common::protobuf::GLogConfig::VERBOSE,
104 std::ostream* os = 0)
106 boost::recursive_mutex::scoped_lock l(goby::common::logger::mutex);
107 sb_.
add_stream(static_cast<logger::Verbosity>(verbosity), os);
120 std::ostream& operator<<(std::ostream& (*pf)(std::ostream&));
123 std::ostream& operator<<(
bool& val) {
return std::ostream::operator<<(val); }
124 std::ostream& operator<<(
const short& val) {
return std::ostream::operator<<(val); }
125 std::ostream& operator<<(
const unsigned short& val) {
return std::ostream::operator<<(val); }
126 std::ostream& operator<<(
const int& val) {
return std::ostream::operator<<(val); }
127 std::ostream& operator<<(
const unsigned int& val) {
return std::ostream::operator<<(val); }
128 std::ostream& operator<<(
const long& val) {
return std::ostream::operator<<(val); }
129 std::ostream& operator<<(
const unsigned long& val) {
return std::ostream::operator<<(val); }
130 std::ostream& operator<<(
const float& val) {
return std::ostream::operator<<(val); }
131 std::ostream& operator<<(
const double& val) {
return std::ostream::operator<<(val); }
132 std::ostream& operator<<(
const long double& val) {
return std::ostream::operator<<(val); }
133 std::ostream& operator<<(std::streambuf* sb) {
return std::ostream::operator<<(sb); }
134 std::ostream& operator<<(std::ios& (*pf)(std::ios&)) {
return std::ostream::operator<<(pf); }
135 std::ostream& operator<<(std::ios_base& (*pf)(std::ios_base&))
137 return std::ostream::operator<<(pf);
144 boost::recursive_mutex&
mutex() {
return logger::mutex; }
147 void set_lock_action(logger_lock::LockAction lock_action) { sb_.set_lock_action(lock_action); }
150 void refresh() { sb_.
refresh(); }
151 void set_group(
const std::string& s) { sb_.
group_name(s); }
153 void set_unset_verbosity()
155 if (sb_.verbosity_depth() == goby::common::logger::UNKNOWN)
156 this->is(goby::common::logger::VERBOSE);
163 bool quiet() {
return (sb_.
is_quiet()); }
165 template <
typename T>
friend void boost::checked_delete(T*);
167 friend std::ostream& operator<<(
FlexOstream& out,
char c);
168 friend std::ostream& operator<<(
FlexOstream& out,
signed char c);
169 friend std::ostream& operator<<(
FlexOstream& out,
unsigned char c);
170 friend std::ostream& operator<<(
FlexOstream& out,
const char* s);
171 friend std::ostream& operator<<(
FlexOstream& out,
const signed char* s);
172 friend std::ostream& operator<<(
FlexOstream& out,
const unsigned char* s);
175 static int instances_;
179 logger_lock::LockAction lock_action_;
182 inline std::ostream& operator<<(
FlexOstream& out,
char c) {
return std::operator<<(out, c); }
183 inline std::ostream& operator<<(
FlexOstream& out,
signed char c) {
return std::operator<<(out, c); }
184 inline std::ostream& operator<<(
FlexOstream& out,
unsigned char c)
186 return std::operator<<(out, c);
188 inline std::ostream& operator<<(
FlexOstream& out,
const char* s) {
return std::operator<<(out, s); }
189 inline std::ostream& operator<<(
FlexOstream& out,
const signed char* s)
191 return std::operator<<(out, s);
193 inline std::ostream& operator<<(
FlexOstream& out,
const unsigned char* s)
195 return std::operator<<(out, s);
199 template <
typename _CharT,
typename _Traits,
typename _Alloc>
201 const std::basic_string<_CharT, _Traits, _Alloc>& s)
203 return std::operator<<(out, s);
224 : original_(original), has_warnings_(
false), has_errors_(
false)
228 void AddError(
int line,
int column,
const std::string& message)
230 using goby::common::logger::WARN;
232 print_original(line, column);
234 << message << std::endl;
237 void AddWarning(
int line,
int column,
const std::string& message)
239 using goby::common::logger::WARN;
241 print_original(line, column);
243 << message << std::endl;
245 has_warnings_ =
true;
248 void print_original(
int line,
int column)
250 using goby::common::logger::WARN;
252 std::stringstream ss(original_ +
"\n");
253 std::string line_str;
259 while (!getline(ss, line_str).eof())
263 << std::setw(3) << i++ <<
"]" << line_str
267 << line_str << std::endl;
271 bool has_errors() {
return has_errors_; }
272 bool has_warnings() {
return has_warnings_; }
275 const std::string& original_;
void refresh()
refresh the display (does nothing if !is_gui())
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
void name(const std::string &s)
name of the application being served
Forms the basis of the Goby logger: std::ostream derived class for holding the FlexOStreamBuf.
void group_name(const std::string &s)
current group name (last insertion of group("") into the stream)
boost::recursive_mutex & mutex()
Get a reference to the Goby logger mutex for scoped locking.
std::ostream & lt_red(std::ostream &os)
All text following this manipulator is light red (e.g. std::cout << lt_red << "text";) ...
void add_stream(logger::Verbosity verbosity, std::ostream *os)
add a stream to the logger
Color
The eight terminal colors (and bold or "light" variants)
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...
bool is_quiet() const
do all attached streams have Verbosity == quiet?
common::FlexOstream glog
Access the Goby logger through this object.
The global namespace for the Goby project.
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...
std::ostream & nocolor(std::ostream &os)
All text following this manipulator is uncolored (e.g. std::cout << green << "green" << nocolor << "u...