00001 #ifndef EDG_WORKLOAD_COMMON_LOGGER_COMMON_H
00002 #define EDG_WORKLOAD_COMMON_LOGGER_COMMON_H
00003
00004 #include <cstdio>
00005
00006 #include <string>
00007
00008 #include <boost/shared_ptr.hpp>
00009
00010 #include "edg/workload/common/common_namespace.h"
00011
00012 COMMON_NAMESPACE_BEGIN {
00013
00014 namespace logger {
00015
00016 class StatePusher;
00017
00018 enum level_t {
00019 null, fatal = null,
00020 verylow, critical = verylow,
00021 low, severe = low,
00022 medium, error = medium,
00023 high, warning = high,
00024 ugly, info = ugly,
00025 veryugly, debug = veryugly,
00026 _last_level
00027 };
00028
00029 class DataContainerImpl {
00030 public:
00031 DataContainerImpl( void );
00032 virtual ~DataContainerImpl( void );
00033
00034
00035 virtual void date( bool b ) = 0;
00036 virtual void multiline( bool b, const char *prefix ) = 0;
00037 virtual void next_level( level_t lev ) = 0;
00038 virtual void time_format( const char *format ) = 0;
00039 virtual void function( const char *func ) = 0;
00040 virtual void clear_function( void ) = 0;
00041
00042
00043 virtual bool date( void ) const = 0;
00044 virtual bool multiline( void ) const = 0;
00045 virtual level_t next_level( void ) const = 0;
00046 virtual const std::string &time_format( void ) const = 0;
00047 virtual const std::string &function( void ) const = 0;
00048 virtual const std::string &multiline_prefix( void ) const = 0;
00049 virtual bool current_tid(std::string &tid) const = 0;
00050
00051
00052 virtual bool date( void ) = 0;
00053 virtual bool multiline( void ) = 0;
00054 virtual level_t next_level( void ) = 0;
00055 virtual const std::string &time_format( void ) = 0;
00056 virtual const std::string &function( void ) = 0;
00057 virtual const std::string &multiline_prefix( void ) = 0;
00058 virtual bool current_tid(std::string &tid) = 0;
00059
00060 void copy( const DataContainerImpl &dci );
00061 };
00062
00063 class DataContainerSingle : public DataContainerImpl {
00064 friend class StatePusher;
00065
00066 public:
00067 DataContainerSingle( const char *format );
00068 ~DataContainerSingle( void );
00069
00070
00071 virtual void date( bool d );
00072 virtual void multiline( bool b, const char *prefix );
00073 virtual void next_level( level_t lev );
00074 virtual void time_format( const char *format );
00075 virtual void function( const char *func );
00076 virtual void clear_function( void );
00077
00078
00079 virtual bool date( void ) const;
00080 virtual bool multiline( void ) const;
00081 virtual level_t next_level( void ) const;
00082 virtual const std::string &time_format( void ) const;
00083 virtual const std::string &function( void ) const;
00084 virtual const std::string &multiline_prefix( void ) const;
00085 virtual bool current_tid(std::string &tid) const;
00086
00087
00088 virtual bool date( void );
00089 virtual bool multiline( void );
00090 virtual level_t next_level( void );
00091 virtual const std::string &time_format( void );
00092 virtual const std::string &function( void );
00093 virtual const std::string &multiline_prefix( void );
00094 virtual bool current_tid(std::string &tid);
00095
00096 private:
00097 DataContainerSingle( void );
00098
00099 bool dcs_date, dcs_multiline;
00100 level_t dcs_next;
00101 std::string dcs_format, dcs_function, dcs_multiprefix;
00102 };
00103
00104 class data_c {
00105 public:
00106 data_c( void );
00107 data_c( const char *name, level_t lev, const char *format );
00108
00109 ~data_c( void );
00110
00111
00112 inline void bad( bool b ) { this->bd_bad = b; }
00113 inline void date( bool d ) { this->bd_data->date( d ); }
00114 inline void show_severity( bool show ) { this->bd_showSeverity = show; }
00115 inline void multiline( bool d, const char *prefix ) { this->bd_data->multiline( d, prefix ); }
00116 inline void next_level( level_t lev ) { this->bd_data->next_level( lev ); }
00117 inline void buffer_level( level_t lev ) { this->bd_current = lev; }
00118 inline void max_size( size_t s ) { this->bd_maxSize = s; }
00119 inline void add_to_total( size_t add ) { this->bd_total += add; }
00120 inline void function( const char *func ) { this->bd_data->function( func ); }
00121 inline void time_format( const char *format ) { this->bd_data->time_format( format ); }
00122 inline void clear_function( void ) { this->bd_data->clear_function(); }
00123
00124
00125 inline bool bad( void ) const { return this->bd_bad; }
00126 inline bool date( void ) const { return this->bd_data->date(); }
00127 inline bool show_severity( void ) const { return this->bd_showSeverity; }
00128 inline bool multiline( void ) const { return this->bd_data->multiline(); }
00129 inline size_t max_size( void ) const { return this->bd_maxSize; }
00130 inline size_t total_size( void ) const { return this->bd_total; }
00131 inline size_t buffer_size( void ) const { return bd_s_bufsize; }
00132 inline level_t next_level( void ) const { return this->bd_data->next_level(); }
00133 inline level_t buffer_level( void ) const { return this->bd_current; }
00134 inline const char *buffer_base( void ) const { return this->bd_buffer; }
00135 inline const std::string &time_format( void ) const { return this->bd_data->time_format(); }
00136 inline const std::string &function( void ) const { return this->bd_data->function(); }
00137 inline const std::string &multiline_prefix( void ) const { return this->bd_data->multiline_prefix(); }
00138 inline bool current_tid(std::string &tid) const { return this->bd_data->current_tid(tid); }
00139
00140
00141
00142 inline bool bad( void ) { return this->bd_bad; }
00143 inline bool date( void ) { return this->bd_data->date(); }
00144 inline bool show_severity( void ) { return this->bd_showSeverity; }
00145 inline bool multiline( void ) { return this->bd_data->multiline(); }
00146 inline size_t max_size( void ) { return this->bd_maxSize; }
00147 inline size_t total_size( void ) { return this->bd_total; }
00148 inline size_t buffer_size( void ) { return bd_s_bufsize; }
00149 inline level_t next_level( void ) { return this->bd_data->next_level(); }
00150 inline level_t buffer_level( void ) { return this->bd_current; }
00151 inline char *buffer_base( void ) { return this->bd_buffer; }
00152 inline DataContainerImpl *container( void ) { return this->bd_data; }
00153 inline const std::string &time_format( void ) { return this->bd_data->time_format(); }
00154 inline const std::string &function( void ) { return this->bd_data->function(); }
00155 inline const std::string &multiline_prefix( void ) { return this->bd_data->multiline_prefix(); }
00156 inline bool current_tid(std::string &tid) { return this->bd_data->current_tid(tid); }
00157
00158 void reset_container( DataContainerImpl *dc );
00159 void reset( const char *name, level_t lev, const char *format );
00160 void remove( void );
00161
00162 static const char *bd_s_timeFormat;
00163
00164 private:
00165 data_c( const data_c &bd );
00166 data_c &operator=( const data_c &bd );
00167
00168 static const size_t bd_s_bufsize = BUFSIZ, bd_s_maxSize = (1024 * 1024);
00169
00170 bool bd_bad, bd_remove, bd_showSeverity;
00171 level_t bd_current;
00172 size_t bd_maxSize, bd_total;
00173 DataContainerImpl *bd_data;
00174 std::string bd_filename;
00175 char bd_buffer[bd_s_bufsize];
00176 };
00177
00178 };
00179
00180 } COMMON_NAMESPACE_END;
00181
00182 #endif
00183
00184
00185
00186