00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef LOGGER_IMPL_H
00015 #define LOGGER_IMPL_H
00016
00017 #include <errno.h>
00018 #include <string>
00019
00020 #if defined(sun)
00021 #include <sys/varargs.h>
00022 #endif
00023
00024 #if defined (__CYGWIN32__) || defined (__NetBSD__)
00025 # include <stdarg.h>
00026 #endif
00027
00028 using std::string;
00029 using std::ostream;
00030
00031 #include "assa/LogMask.h"
00032
00033 namespace ASSA {
00034
00035 class Reactor;
00036
00037 class Logger_Impl {
00038 public:
00045 static const unsigned int LOGGER_MAXLINE = 6660;
00046
00047 public:
00048 Logger_Impl ();
00049 virtual ~Logger_Impl () { }
00050
00051 void enable_group (Group g_) { m_groups |= g_; }
00052 void disable_group (Group g_) { m_groups &= ~g_; }
00053
00054 void enable_groups (u_long g_) { m_groups |= g_; }
00055 void disable_groups (u_long g_) { m_groups &= ~g_; }
00056
00057 void enable_all_groups (void) { m_groups = ASSA::ALL; }
00058 void disable_all_groups (void) { m_groups = 0; }
00059
00060 bool group_enabled (Group g_) const { return (m_groups & g_); }
00061
00062 void enable_timestamp (void) { m_tmflg = true; }
00063 void disable_timestamp (void) { m_tmflg = false; }
00064 bool timestamp_enabled (void) const { return m_tmflg; }
00065 void set_timezone (int zone_) { m_tz = zone_; }
00066
00067 void set_indent_step (u_short step_) { m_indent_step = step_; }
00068 u_short get_indent_step (void) const { return m_indent_step; }
00069
00071 virtual int log_open (u_long groups_);
00072
00074 virtual int log_open (const char* logfname_,
00075 u_long groups_,
00076 u_long maxsize_);
00077
00079 virtual int log_open (const char* appname_,
00080 const char* logfname_,
00081 u_long groups_,
00082 u_long maxsize_,
00083 Reactor* reactor_);
00084
00085 virtual int log_close (void) = 0;
00086 virtual void log_resync (void) { }
00087
00088 virtual int log_msg (Group g_,
00089 size_t indent_level_,
00090 const string& func_name_,
00091 size_t expected_sz_,
00092 const char* fmt_,
00093 va_list) = 0;
00094
00095 virtual int log_func (Group g_,
00096 size_t indent_level_,
00097 const string& func_name_,
00098 marker_t type_) = 0;
00099 protected:
00100 virtual u_short add_timestamp (ostream& sink_);
00101 virtual u_short indent_func_name (ostream& sink_,
00102 const string& funcname_,
00103 size_t indent_level_,
00104 marker_t type_);
00105
00122 char* format_msg (size_t expected_sz_,
00123 const char* fmt_,
00124 va_list vap_,
00125 bool& release_);
00126
00127 protected:
00129 static char m_msgbuf [LOGGER_MAXLINE];
00130
00132 u_short m_indent_step;
00133
00135 u_long m_groups;
00136
00138 string m_logfname;
00139
00141 bool m_tmflg;
00142
00144 int m_tz;
00145 };
00146
00147 inline
00148 Logger_Impl::
00149 Logger_Impl ()
00150 : m_indent_step (1),
00151 m_groups (0),
00152 m_tmflg (false),
00153 m_tz (1)
00154 {
00155
00156 }
00157
00158 inline int
00159 Logger_Impl::
00160 log_open (u_long )
00161 {
00162 errno = ENOSYS;
00163 return -1;
00164 }
00165
00166 inline int
00167 Logger_Impl::
00168 log_open (const char*,
00169 u_long,
00170 u_long )
00171 {
00172 errno = ENOSYS;
00173 return -1;
00174 }
00175
00176 inline int
00177 Logger_Impl::
00178 log_open (const char*,
00179 const char*,
00180 u_long,
00181 u_long,
00182 Reactor* )
00183 {
00184 errno = ENOSYS;
00185 return -1;
00186 }
00187
00188 }
00189
00190 #endif