27 #ifndef LUNCHBOX_LOG_H
28 #define LUNCHBOX_LOG_H
69 : _line(0), _indent(0), _blocked(0), _noHeader(0),
70 _newLine(
true), _stream(stream)
74 void indent() { ++_indent; }
75 void exdent() { --_indent; }
77 void disableFlush() { ++_blocked; assert( _blocked < 100 ); }
84 void disableHeader() { ++_noHeader; }
85 void enableHeader() { --_noHeader; }
87 LUNCHBOX_API
void setThreadName(
const std::string& name );
88 const char* getThreadName()
const {
return _thread; }
90 LUNCHBOX_API
void setLogInfo(
const char* file,
const int line );
93 virtual int_type overflow( LogBuffer::int_type c );
123 std::ostringstream _stringStream;
126 std::ostream& _stream;
133 class Log :
public std::ostream
137 Log() : std::ostream( &_logBuffer ), _logBuffer(
getOutput( )){}
138 virtual ~
Log() { _logBuffer.pubsync(); }
140 void indent() { _logBuffer.indent(); }
141 void exdent() { _logBuffer.exdent(); }
142 void disableFlush() { _logBuffer.disableFlush(); }
143 void enableFlush() { _logBuffer.enableFlush(); }
144 void forceFlush() { _logBuffer.pubsync(); }
145 void disableHeader() { _logBuffer.disableHeader(); }
146 void enableHeader() { _logBuffer.enableHeader(); }
158 static LUNCHBOX_API
Log&
instance(
const char* file,
const int line );
161 static LUNCHBOX_API
void exit();
164 static LUNCHBOX_API
void reset();
173 static LUNCHBOX_API
void setOutput( std::ostream& stream );
176 static LUNCHBOX_API
bool setOutput(
const std::string& file );
179 static LUNCHBOX_API std::ostream&
getOutput ();
191 static const Clock& getClock();
194 void setThreadName(
const std::string& name )
195 { _logBuffer.setThreadName( name ); }
198 const char* getThreadName()
const {
return _logBuffer.getThreadName(); }
201 LogBuffer _logBuffer;
204 Log& operator = (
const Log& );
206 void setLogInfo(
const char* file,
const int line )
207 { _logBuffer.setLogInfo( file, line ); }
215 LUNCHBOX_API std::ostream&
indent( std::ostream& os );
217 LUNCHBOX_API std::ostream&
exdent( std::ostream& os );
220 LUNCHBOX_API std::ostream&
disableFlush( std::ostream& os );
222 LUNCHBOX_API std::ostream&
enableFlush( std::ostream& os );
224 LUNCHBOX_API std::ostream&
forceFlush( std::ostream& os );
227 LUNCHBOX_API std::ostream&
disableHeader( std::ostream& os );
229 LUNCHBOX_API std::ostream&
enableHeader( std::ostream& os );
233 #define LBERROR (lunchbox::Log::level >= lunchbox::LOG_ERROR) && \
234 lunchbox::Log::instance( __FILE__, __LINE__ )
236 #define LBWARN (lunchbox::Log::level >= lunchbox::LOG_WARN) && \
237 lunchbox::Log::instance( __FILE__, __LINE__ )
239 #define LBINFO (lunchbox::Log::level >= lunchbox::LOG_INFO) && \
240 lunchbox::Log::instance( __FILE__, __LINE__ )
243 # define LBVERB if( false ) \
244 lunchbox::Log::instance( __FILE__, __LINE__ )
247 # define LBVERB (lunchbox::Log::level >= lunchbox::LOG_VERB) && \
248 lunchbox::Log::instance( __FILE__, __LINE__ )
255 #define LBLOG(topic) (lunchbox::Log::topics & (topic)) && \
256 lunchbox::Log::instance( __FILE__, __LINE__ )
262 #define LBTHROW(exc) \
264 LBLOG(lunchbox::LOG_EXCEPTION) << exc.what() << std::endl; \
268 #endif //LUNCHBOX_LOG_H