00001 #ifndef EDG_WORKLOAD_COMMON_LOGGER_LOGBUF_H
00002 #define EDG_WORKLOAD_COMMON_LOGGER_LOGBUF_H
00003
00004 #include <iostream>
00005
00006 #include "common.h"
00007
00008 COMMON_NAMESPACE_BEGIN {
00009
00010 namespace logger {
00011
00012 class Logbuf : public std::streambuf {
00013 public:
00014 Logbuf( void );
00015 Logbuf( const char *filename, level_t lev, const char *format = data_c::bd_s_timeFormat );
00016 Logbuf( std::streambuf *buffer, level_t lev, const char *format = data_c::bd_s_timeFormat );
00017
00018 virtual ~Logbuf( void );
00019
00020 Logbuf *open( const char *name, level_t lev, const char *format = data_c::bd_s_timeFormat );
00021 Logbuf *open( std::streambuf *buffer, level_t lev, const char *format = data_c::bd_s_timeFormat );
00022 Logbuf *close( void );
00023 Logbuf *activate_log_rotation( std::streamsize maxsize, const std::string &basename, unsigned int maxfiles );
00024 Logbuf *deactivate_log_rotation( void );
00025 int log_rotate( void );
00026
00027 inline void show_severity( bool show ) { this->lb_data.show_severity( show ); }
00028 inline void multiline( bool multi, const char *prefix = NULL ) { this->lb_data.multiline( multi, prefix ); }
00029 inline void next_level( level_t lev ) { this->lb_data.next_level( lev ); }
00030 inline void buffer_level( level_t lev ) { this->lb_data.buffer_level( lev ); }
00031 inline void function( const char *func ) { this->lb_data.function( func ); }
00032 inline void time_format( const char *format ) { this->lb_data.time_format( format ); }
00033 inline void clear_function( void ) { this->lb_data.clear_function(); }
00034 inline void reset_container( DataContainerImpl *dc ) { this->lb_data.reset_container( dc ); }
00035 inline bool bad( void ) { return this->lb_data.bad(); }
00036 inline DataContainerImpl *container( void ) { return this->lb_data.container(); }
00037
00038 protected:
00039 virtual int overflow( int ch );
00040 virtual int sync( void );
00041
00042 private:
00043 void writeBuffer( std::streamoff n );
00044 bool checkRotationBuffer( void );
00045 int internalSync( bool );
00046 std::streamsize getBufferSize( void );
00047
00048 Logbuf( const Logbuf &lb );
00049 Logbuf &operator=( const Logbuf &lb );
00050
00051 static const char *lb_s_letterLevels;
00052
00053 bool lb_remove, lb_rotate;
00054 unsigned int lb_maxfiles;
00055 std::streamsize lb_current, lb_maxsize;
00056 std::streambuf *lb_buffer;
00057 std::string lb_basename;
00058 data_c lb_data;
00059 };
00060
00061 };
00062
00063 } COMMON_NAMESPACE_END;
00064
00065 #endif
00066
00067
00068
00069