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
00050
00051 virtual bool date( void ) = 0;
00052 virtual bool multiline( void ) = 0;
00053 virtual level_t next_level( void ) = 0;
00054 virtual const std::string &time_format( void ) = 0;
00055 virtual const std::string &function( void ) = 0;
00056 virtual const std::string &multiline_prefix( void ) = 0;
00057
00058 void copy( const DataContainerImpl &dci );
00059 };
00060
00061 class DataContainerSingle : public DataContainerImpl {
00062 friend class StatePusher;
00063
00064 public:
00065 DataContainerSingle( const char *format );
00066 ~DataContainerSingle( void );
00067
00068
00069 virtual void date( bool d );
00070 virtual void multiline( bool b, const char *prefix );
00071 virtual void next_level( level_t lev );
00072 virtual void time_format( const char *format );
00073 virtual void function( const char *func );
00074 virtual void clear_function( void );
00075
00076
00077 virtual bool date( void ) const;
00078 virtual bool multiline( void ) const;
00079 virtual level_t next_level( void ) const;
00080 virtual const std::string &time_format( void ) const;
00081 virtual const std::string &function( void ) const;
00082 virtual const std::string &multiline_prefix( void ) const;
00083
00084
00085 virtual bool date( void );
00086 virtual bool multiline( void );
00087 virtual level_t next_level( void );
00088 virtual const std::string &time_format( void );
00089 virtual const std::string &function( void );
00090 virtual const std::string &multiline_prefix( void );
00091
00092 private:
00093 DataContainerSingle( void );
00094
00095 bool dcs_date, dcs_multiline;
00096 level_t dcs_next;
00097 std::string dcs_format, dcs_function, dcs_multiprefix;
00098 };
00099
00100 class data_c {
00101 public:
00102 data_c( void );
00103 data_c( const char *name, level_t lev, const char *format );
00104
00105 ~data_c( void );
00106
00107
00108 inline void bad( bool b ) { this->bd_bad = b; }
00109 inline void date( bool d ) { this->bd_data->date( d ); }
00110 inline void show_severity( bool show ) { this->bd_showSeverity = show; }
00111 inline void multiline( bool d, const char *prefix ) { this->bd_data->multiline( d, prefix ); }
00112 inline void next_level( level_t lev ) { this->bd_data->next_level( lev ); }
00113 inline void buffer_level( level_t lev ) { this->bd_current = lev; }
00114 inline void max_size( size_t s ) { this->bd_maxSize = s; }
00115 inline void add_to_total( size_t add ) { this->bd_total += add; }
00116 inline void function( const char *func ) { this->bd_data->function( func ); }
00117 inline void time_format( const char *format ) { this->bd_data->time_format( format ); }
00118 inline void clear_function( void ) { this->bd_data->clear_function(); }
00119
00120
00121 inline bool bad( void ) const { return this->bd_bad; }
00122 inline bool date( void ) const { return this->bd_data->date(); }
00123 inline bool show_severity( void ) const { return this->bd_showSeverity; }
00124 inline bool multiline( void ) const { return this->bd_data->multiline(); }
00125 inline size_t max_size( void ) const { return this->bd_maxSize; }
00126 inline size_t total_size( void ) const { return this->bd_total; }
00127 inline size_t buffer_size( void ) const { return bd_s_bufsize; }
00128 inline level_t next_level( void ) const { return this->bd_data->next_level(); }
00129 inline level_t buffer_level( void ) const { return this->bd_current; }
00130 inline const char *buffer_base( void ) const { return this->bd_buffer; }
00131 inline const std::string &time_format( void ) const { return this->bd_data->time_format(); }
00132 inline const std::string &function( void ) const { return this->bd_data->function(); }
00133 inline const std::string &multiline_prefix( void ) const { return this->bd_data->multiline_prefix(); }
00134
00135
00136 inline bool bad( void ) { return this->bd_bad; }
00137 inline bool date( void ) { return this->bd_data->date(); }
00138 inline bool show_severity( void ) { return this->bd_showSeverity; }
00139 inline bool multiline( void ) { return this->bd_data->multiline(); }
00140 inline size_t max_size( void ) { return this->bd_maxSize; }
00141 inline size_t total_size( void ) { return this->bd_total; }
00142 inline size_t buffer_size( void ) { return bd_s_bufsize; }
00143 inline level_t next_level( void ) { return this->bd_data->next_level(); }
00144 inline level_t buffer_level( void ) { return this->bd_current; }
00145 inline char *buffer_base( void ) { return this->bd_buffer; }
00146 inline DataContainerImpl *container( void ) { return this->bd_data; }
00147 inline const std::string &time_format( void ) { return this->bd_data->time_format(); }
00148 inline const std::string &function( void ) { return this->bd_data->function(); }
00149 inline const std::string &multiline_prefix( void ) { return this->bd_data->multiline_prefix(); }
00150
00151 void reset_container( DataContainerImpl *dc );
00152 void reset( const char *name, level_t lev, const char *format );
00153 void remove( void );
00154
00155 static const char *bd_s_timeFormat;
00156
00157 private:
00158 data_c( const data_c &bd );
00159 data_c &operator=( const data_c &bd );
00160
00161 static const size_t bd_s_bufsize = BUFSIZ, bd_s_maxSize = (1024 * 1024);
00162
00163 bool bd_bad, bd_remove, bd_showSeverity;
00164 level_t bd_current;
00165 size_t bd_maxSize, bd_total;
00166 DataContainerImpl *bd_data;
00167 std::string bd_filename;
00168 char bd_buffer[bd_s_bufsize];
00169 };
00170
00171 };
00172
00173 } COMMON_NAMESPACE_END;
00174
00175 #endif
00176
00177
00178
00179