ASSA::Logger Class Reference

#include <Logger.h>

Inheritance diagram for ASSA::Logger:

ASSA::Singleton< Logger > List of all members.

Public Member Functions

 Logger ()
 ~Logger ()
void set_app_name (const std::string &appname_)
 Set application name.
void enable_group (Group g_)
 Enable logging for group g_.
void disable_group (Group g_)
 Disable logging for group g_.
void enable_groups (u_long groups_)
 Enable logging for groups_.
void disable_groups (u_long groups_)
 Disable logging for groups_.
void enable_all_groups (void)
void disable_all_groups (void)
bool group_enabled (Group g_) const
void enable_timestamp (void)
 Add optional timezone: GMT vs. Local.
void disable_timestamp (void)
bool timestamp_enabled (void) const
void set_timezone (int zone)
 0 - GMT, 1 - LOCAL
void sign_on (const string &func_name_)
void sign_off (void)
int log_open (u_long groups_)
 Write log messages to standard output.
int log_open (const char *logfname_, u_long groups_, u_long maxsize_)
 Write log messages to the logfile.
int log_open (const std::string &logsvr_, const char *logfname_, u_long groups_, u_long maxsize_, Reactor *reactor_)
 Write log messages to the log server assa-logd.
void log_resync (void)
int log_close (void)
int log_msg (u_long g_, const char *fmt_,...)
 Here is an interesting twist introduced by remote logging server:.
int log_func (u_long g_, marker_t type_)

Private Attributes

Logger_Implm_impl
stack< string > m_context
 Logger implementation.
std::string m_app_name
 Stack of all contexts.

Detailed Description

Definition at line 45 of file Logger.h.


Constructor & Destructor Documentation

ASSA::Logger::Logger  )  [inline]
 

Definition at line 48 of file Logger.h.

00048 : m_impl (NULL), m_app_name ("zombie") { /* no-op */ }

ASSA::Logger::~Logger  )  [inline]
 

Definition at line 49 of file Logger.h.

References log_close().

00049 { this->log_close (); }


Member Function Documentation

void ASSA::Logger::disable_all_groups void   )  [inline]
 

Definition at line 196 of file Logger.h.

References ASSA::Logger_Impl::disable_all_groups(), and m_impl.

00197 {
00198     if (m_impl) {
00199         m_impl->disable_all_groups ();
00200     }
00201 }

void ASSA::Logger::disable_group Group  g_  )  [inline]
 

Disable logging for group g_.

Parameters:
g_ Group to disable

Definition at line 153 of file Logger.h.

References ASSA::Logger_Impl::disable_group(), and m_impl.

00154 {
00155     if (m_impl) {
00156         m_impl->disable_group (g_);
00157     }
00158 }

void ASSA::Logger::disable_groups u_long  groups_  )  [inline]
 

Disable logging for groups_.

Parameters:
groups_ Groups to disable

Definition at line 171 of file Logger.h.

References ASSA::Logger_Impl::disable_groups(), and m_impl.

00172 {
00173     if (m_impl) {
00174         m_impl->disable_groups (g_);
00175     }
00176 }

void ASSA::Logger::disable_timestamp void   )  [inline]
 

Definition at line 214 of file Logger.h.

References ASSA::Logger_Impl::disable_timestamp(), and m_impl.

00215 {
00216     if (m_impl) {
00217         m_impl->disable_timestamp ();
00218     }
00219 }

void ASSA::Logger::enable_all_groups void   )  [inline]
 

Definition at line 187 of file Logger.h.

References ASSA::Logger_Impl::enable_all_groups(), and m_impl.

00188 {
00189     if (m_impl) {
00190         m_impl->enable_all_groups ();
00191     }
00192 }

void ASSA::Logger::enable_group Group  g_  )  [inline]
 

Enable logging for group g_.

Parameters:
g_ Group to enable

Definition at line 144 of file Logger.h.

References ASSA::Logger_Impl::enable_group(), and m_impl.

00145 { 
00146     if (m_impl) {
00147         m_impl->enable_group (g_);
00148     }
00149 }

void ASSA::Logger::enable_groups u_long  groups_  )  [inline]
 

Enable logging for groups_.

Parameters:
groups_ Groups to enable

Definition at line 162 of file Logger.h.

References ASSA::Logger_Impl::enable_groups(), and m_impl.

00163 { 
00164     if (m_impl) {
00165         m_impl->enable_groups (g_);
00166     }
00167 }

void ASSA::Logger::enable_timestamp void   )  [inline]
 

Add optional timezone: GMT vs. Local.

Definition at line 205 of file Logger.h.

References ASSA::Logger_Impl::enable_timestamp(), and m_impl.

00206 {
00207     if (m_impl) {
00208         m_impl->enable_timestamp ();
00209     }
00210 }

bool ASSA::Logger::group_enabled Group  g_  )  const [inline]
 

Definition at line 180 of file Logger.h.

References ASSA::Logger_Impl::group_enabled(), and m_impl.

00181 {
00182     return (m_impl) ? m_impl->group_enabled (g_) : false;
00183 }

int Logger::log_close void   ) 
 

Definition at line 34 of file Logger.cpp.

References ASSA::Logger_Impl::log_close(), and m_impl.

Referenced by ~Logger().

00035 {
00036     int ret = 0;
00037 
00038     if (m_impl) {
00039         ret = m_impl->log_close ();
00040         delete m_impl;
00041         m_impl = 0;
00042     }
00043     return ret;
00044 }

int Logger::log_func u_long  g_,
marker_t  type_
 

Definition at line 148 of file Logger.cpp.

References ASSA::Logger_Impl::log_func(), m_context, and m_impl.

00149 {
00150     std::string empty_str;
00151     if (m_impl == NULL) {
00152         return -1;
00153     }
00154     return  m_impl->log_func (static_cast<Group> (g_), m_context.size (),
00155                               m_context.size () ? m_context.top () : empty_str,
00156                               type_);
00157 }

int Logger::log_msg u_long  g_,
const char *  fmt_,
  ...
 

Here is an interesting twist introduced by remote logging server:.

Setting errno bits puts us in an unexpected situation. Asynchronous connection establishment reliest on examening errno to see if it was set by the system call, connect(), to EINPROGRESS. If it was, and thus connect() failed, IPv4Socket::connect() would log it as an error with EL() macro. When client is configured to log its messages to the server, call to EL() would result into the call to log_msg(), and because connection to the server has not yet been established, m_impl is set to 0 and errno is reset to EPERM. When stack unwinds itself, Connector::connect() fails because Connector::connectServiceHandler() returned errno different from expected EINPROGRESS (it is EPERM)!

From vprintf(3S) manpage: "The vsnprintf() function returns the number of characters formatted, that is, then number of characters that would have been written to the buffer if it were large enough. It returns a negative value if an output error was encountered."

Definition at line 117 of file Logger.cpp.

References ASSA::Logger_Impl::log_msg(), m_context, and m_impl.

00118 {
00119     if (m_impl == NULL) {
00120         return -1;
00121     }
00122     int ret;
00123     string empty_str;
00124     va_list ap;
00125     size_t expected_sz = 0;
00126     char c;
00127 
00134     va_start (ap, fmt_);
00135     expected_sz = ::vsnprintf (&c, 1, fmt_, ap) + 1;
00136     va_end (ap);
00137 
00138     va_start (ap, fmt_);
00139     ret = m_impl->log_msg (static_cast<Group> (g_), m_context.size (),
00140                            m_context.size () ? m_context.top () : empty_str,
00141                            expected_sz, fmt_, ap);
00142     va_end (ap);
00143     return ret;
00144 }

int Logger::log_open const std::string &  logsvr_,
const char *  logfname_,
u_long  groups_,
u_long  maxsize_,
Reactor reactor_
 

Write log messages to the log server assa-logd.

Parameters:
logsvr_ Address of assa-logd (assalogd@hostname)
logfname_ Name of the logfile
groups_ Logging masks enabled
maxsize_ Maximum size of the logfile
reactor_ Pointer to the Reactor to use for communication.
Returns:
: 0 on success; -1 on error with errno set

Definition at line 72 of file Logger.cpp.

References ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::connect(), ASSA::AutoPtr< X >::get(), m_impl, ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::open(), and ASSA::AutoPtr< X >::release().

00077 {
00078     {
00079         TimeVal tv (10.0);
00080         INETAddress addr (logsvraddr_.c_str ());
00081         if (addr.bad ()) {
00082             return -1;
00083         }
00084         Connector <RemoteLogger, IPv4Socket> log_connector;
00085         AutoPtr<RemoteLogger> lsp (new RemoteLogger);
00086         log_connector.open (tv);
00087         if (log_connector.connect (lsp.get (), addr) < 0) {
00088             delete m_impl;
00089             m_impl = NULL;
00090             return -1;
00091         }
00092         m_impl = lsp.release ();
00093     }
00094     int ret =  m_impl->log_open (m_app_name.c_str (), logfname_, 
00095                                  groups_, maxsize_, reactor_);
00096     return ret;
00097 }

int Logger::log_open const char *  logfname_,
u_long  groups_,
u_long  maxsize_
 

Write log messages to the logfile.

Parameters:
logfname_ Name of the logfile
groups_ Logging masks enabled
maxsize_ Maximum size of the logfile
Returns:
0 on success, -1 on error with errno set

Definition at line 61 of file Logger.cpp.

References ASSA::Logger_Impl::log_open(), and m_impl.

00062 {
00063     if (m_impl != NULL) {
00064         return -1;
00065     }
00066     m_impl = new FileLogger;
00067     return m_impl->log_open (logfname_, groups_, maxsize_);
00068 }

int Logger::log_open u_long  groups_  ) 
 

Write log messages to standard output.

Returns:
0 on success, -1 on error with errno set

Definition at line 48 of file Logger.cpp.

References ASSA::endl(), ASSA::Logger_Impl::log_open(), and m_impl.

00049 {
00050     if (m_impl != NULL) {
00051         std::cerr << "Logger::log_open - Implementation already exist" 
00052                   << std::endl;
00053         return -1;
00054     }
00055     m_impl = new StdOutLogger;
00056     return m_impl->log_open (groups_);
00057 }

void ASSA::Logger::log_resync void   )  [inline]
 

Definition at line 239 of file Logger.h.

References ASSA::Logger_Impl::log_resync(), and m_impl.

00240 {
00241     if (m_impl) {
00242         m_impl->log_resync ();
00243     }
00244 }

void ASSA::Logger::set_app_name const std::string &  appname_  )  [inline]
 

Set application name.

This should be the first call made to the newly created Logger object.

Definition at line 55 of file Logger.h.

References m_app_name.

00055 { m_app_name = appname_; }

void ASSA::Logger::set_timezone int  zone  )  [inline]
 

0 - GMT, 1 - LOCAL

Definition at line 230 of file Logger.h.

References m_impl, and ASSA::Logger_Impl::set_timezone().

00231 {
00232     if (m_impl) {
00233         m_impl->set_timezone (zone_);
00234     }
00235 }

void ASSA::Logger::sign_off void   )  [inline]
 

Definition at line 255 of file Logger.h.

References m_context.

00256 {
00257     if (!m_context.empty ()) {
00258         m_context.pop ();
00259     }
00260 }

void ASSA::Logger::sign_on const string &  func_name_  )  [inline]
 

Definition at line 248 of file Logger.h.

References m_context.

00249 {
00250     m_context.push (func_name_);
00251 }

bool ASSA::Logger::timestamp_enabled void   )  const [inline]
 

Definition at line 223 of file Logger.h.

References m_impl, and ASSA::Logger_Impl::timestamp_enabled().

00224 {
00225     return (m_impl) ? m_impl->timestamp_enabled () : false;
00226 }


Member Data Documentation

std::string ASSA::Logger::m_app_name [private]
 

Stack of all contexts.

Definition at line 130 of file Logger.h.

Referenced by set_app_name().

stack<string> ASSA::Logger::m_context [private]
 

Logger implementation.

Definition at line 129 of file Logger.h.

Referenced by log_func(), log_msg(), sign_off(), and sign_on().

Logger_Impl* ASSA::Logger::m_impl [private]
 

Definition at line 128 of file Logger.h.

Referenced by disable_all_groups(), disable_group(), disable_groups(), disable_timestamp(), enable_all_groups(), enable_group(), enable_groups(), enable_timestamp(), group_enabled(), log_close(), log_func(), log_msg(), log_open(), log_resync(), set_timezone(), and timestamp_enabled().


The documentation for this class was generated from the following files:
Generated on Wed Jun 21 15:59:00 2006 for libassa by  doxygen 1.4.6