25#ifndef GOBY_UTIL_DEBUG_LOGGER_FLEX_OSTREAM_H
26#define GOBY_UTIL_DEBUG_LOGGER_FLEX_OSTREAM_H
32#include <google/protobuf/io/tokenizer.h>
33#include <google/protobuf/text_format.h>
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 =
"");
97 std::ostream* os =
nullptr)
119 std::ostream&
operator<<(std::ostream& (*pf)(std::ostream&));
122 std::ostream&
operator<<(
bool& val) {
return std::ostream::operator<<(val); }
123 std::ostream&
operator<<(
const short& val) {
return std::ostream::operator<<(val); }
124 std::ostream&
operator<<(
const unsigned short& val) {
return std::ostream::operator<<(val); }
125 std::ostream&
operator<<(
const int& val) {
return std::ostream::operator<<(val); }
126 std::ostream&
operator<<(
const unsigned int& val) {
return std::ostream::operator<<(val); }
127 std::ostream&
operator<<(
const long& val) {
return std::ostream::operator<<(val); }
128 std::ostream&
operator<<(
const long 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);
163 bool quiet() {
return (sb_.
is_quiet()); }
173 static int instances_;
180inline std::ostream& operator<<(
FlexOstream& out,
char c) {
return std::operator<<(out, c); }
181inline std::ostream& operator<<(
FlexOstream& out,
signed char c) {
return std::operator<<(out, c); }
184 return std::operator<<(out, c);
186inline std::ostream& operator<<(
FlexOstream& out,
const char* s) {
return std::operator<<(out, s); }
187inline std::ostream& operator<<(
FlexOstream& out,
const signed char* s)
189 return std::operator<<(out, s);
191inline std::ostream& operator<<(
FlexOstream& out,
const unsigned char* s)
193 return std::operator<<(out, s);
197template <
typename _CharT,
typename _Traits,
typename _Alloc>
199 const std::basic_string<_CharT, _Traits, _Alloc>& s)
201 return std::operator<<(out, s);
209extern util::FlexOstream
glog;
214[[deprecated(
"Use goby::glog")]]
inline util::FlexOstream& glogger() {
return goby::glog; }
219 FlexOStreamErrorCollector(
const std::string& original)
220 : original_(original), has_warnings_(false), has_errors_(false)
224 void AddError(
int line,
int column,
const std::string& message)
override
228 print_original(line, column);
230 << message << std::endl;
233 void AddWarning(
int line,
int column,
const std::string& message)
override
237 print_original(line, column);
239 << message << std::endl;
241 has_warnings_ =
true;
244 void print_original(
int line,
int )
248 std::stringstream ss(original_ +
"\n");
249 std::string line_str;
255 while (!getline(ss, line_str).eof())
259 << std::setw(3) << i++ <<
"]" << line_str
263 << line_str << std::endl;
267 bool has_errors() {
return has_errors_; }
268 bool has_warnings() {
return has_warnings_; }
271 const std::string& original_;
void set_lock_action(logger_lock::LockAction lock_action)
void group_name(const std::string &s)
current group name (last insertion of group("") into the stream)
bool is_quiet() const
do all attached streams have Verbosity == quiet?
void name(const std::string &s)
name of the application being served
void refresh()
refresh the display (does nothing if !is_gui())
void remove_stream(std::ostream *os)
remove a stream from the logger
void add_stream(logger::Verbosity verbosity, std::ostream *os)
add a stream to the logger
Forms the basis of the Goby logger: std::ostream derived class for holding the FlexOStreamBuf.
~FlexOstream() override=default
std::ostream & operator<<(std::ios_base &(*pf)(std::ios_base &))
std::ostream & operator<<(const double &val)
std::ostream & operator<<(FlexOstream &(*pf)(FlexOstream &))
std::ostream & operator<<(const unsigned long &val)
friend std::ostream & operator<<(FlexOstream &out, char c)
void remove_stream(std::ostream *os=nullptr)
std::ostream & operator<<(std::ostream &(*pf)(std::ostream &))
std::ostream & operator<<(const long long &val)
std::ostream & operator<<(const short &val)
std::ostream & operator<<(bool &val)
std::ostream & operator<<(const long &val)
void add_stream(goby::util::protobuf::GLogConfig::Verbosity verbosity=goby::util::protobuf::GLogConfig::VERBOSE, std::ostream *os=nullptr)
std::ostream & operator<<(const int &val)
const FlexOStreamBuf & buf()
std::recursive_mutex & mutex()
Get a reference to the Goby logger mutex for scoped locking.
std::ostream & operator<<(const float &val)
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<<(const long double &val)
std::ostream & operator<<(const unsigned short &val)
bool is(goby::util::logger::Verbosity verbosity)
void set_group(const std::string &s)
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
std::ostream & operator<<(std::streambuf *sb)
std::ostream & operator<<(std::ios &(*pf)(std::ios &))
std::ostream & operator<<(const unsigned int &val)
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=nullptr)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity.
void set_lock_action(logger_lock::LockAction lock_action)
static constexpr Verbosity VERBOSE
LockAction
Mutex actions available to the Goby logger (glogger)
std::recursive_mutex mutex
std::ostream & nocolor(std::ostream &os)
All text following this manipulator is uncolored (e.g. std::cout << green << "green" << nocolor << "u...
std::ostream & lt_red(std::ostream &os)
All text following this manipulator is light red (e.g. std::cout << lt_red << "text";)
The global namespace for the Goby project.
util::FlexOstream glog
Access the Goby logger through this object.
Color
The eight terminal colors (and bold or "light" variants)