ASSA::Logger_Impl Class Reference

#include <Logger_Impl.h>

Inheritance diagram for ASSA::Logger_Impl:
ASSA::FileLogger ASSA::RemoteLogger ASSA::StdOutLogger

List of all members.

Public Member Functions

 Logger_Impl ()
virtual ~Logger_Impl ()
void enable_group (Group g_)
void disable_group (Group g_)
void enable_groups (u_long g_)
void disable_groups (u_long g_)
void enable_all_groups (void)
void disable_all_groups (void)
bool group_enabled (Group g_) const
void enable_timestamp (void)
void disable_timestamp (void)
bool timestamp_enabled (void) const
void set_timezone (int zone_)
void set_indent_step (u_short step_)
u_short get_indent_step (void) const
virtual int log_open (u_long groups_)
 Open StdErr Logger.
virtual int log_open (const char *logfname_, u_long groups_, u_long maxsize_)
 Open File Logger.
virtual int log_open (const char *appname_, const char *logfname_, u_long groups_, u_long maxsize_, Reactor *reactor_)
 Open connection with Log Server.
virtual int log_close (void)=0
virtual void log_resync (void)
virtual int log_msg (Group g_, size_t indent_level_, const string &func_name_, size_t expected_sz_, const char *fmt_, va_list)=0
virtual int log_func (Group g_, size_t indent_level_, const string &func_name_, marker_t type_)=0

Static Public Attributes

static const unsigned int LOGGER_MAXLINE = 6660
 Maximum length of the formatted message.

Protected Member Functions

virtual u_short add_timestamp (ostream &sink_)
virtual u_short indent_func_name (ostream &sink_, const string &funcname_, size_t indent_level_, marker_t type_)
char * format_msg (size_t expected_sz_, const char *fmt_, va_list vap_, bool &release_)
 Format and put the message in the buffer.

Protected Attributes

u_short m_indent_step
 Indentation step.
u_long m_groups
 Enabled groups.
string m_logfname
 Log file name.
bool m_tmflg
 Timestamp on/off flag.
int m_tz
 Timezone: 0-GMT, 1-Local.

Static Protected Attributes

static char m_msgbuf [LOGGER_MAXLINE]
 Static buffer for formatted message.

Detailed Description

Definition at line 140 of file Logger_Impl.h.


Constructor & Destructor Documentation

ASSA::Logger_Impl::Logger_Impl (  )  [inline]

Definition at line 252 of file Logger_Impl.h.

00253     : m_indent_step (1), 
00254       m_groups (0), 
00255       m_tmflg (false), 
00256       m_tz (1)
00257 {
00258     /* no-op */
00259 }

virtual ASSA::Logger_Impl::~Logger_Impl (  )  [inline, virtual]

Definition at line 152 of file Logger_Impl.h.

00152 { /* empty */ }


Member Function Documentation

u_short Logger_Impl::add_timestamp ( ostream &  sink_  )  [protected, virtual]

Definition at line 33 of file Logger_Impl.cpp.

References ASSA::TimeVal::fmtString(), ASSA::TimeVal::gettimeofday(), m_tz, ASSA::TimeVal::msec(), timestamp_enabled(), and ASSA::TimeVal::tz().

Referenced by ASSA::StdOutLogger::log_func(), ASSA::RemoteLogger::log_func(), ASSA::FileLogger::log_func(), ASSA::StdOutLogger::log_msg(), ASSA::RemoteLogger::log_msg(), and ASSA::FileLogger::log_msg().

00034 {
00035     /*--- 'DD/MM/CC HH:MM:SS.MMMM ' - 23 chars ---*/
00036     u_short bytecount = 0;
00037 
00038     if (timestamp_enabled ()) {
00039         TimeVal tv = TimeVal::gettimeofday ();
00040         tv.tz (m_tz);
00041         sink_ << tv.fmtString ("%m/%d/%Y %H:%M:%S") << '.';
00042         char oldfill = sink_.fill('0');
00043         sink_ << std::setw (3) << (tv.msec () % 1000000)/1000 << ' ';
00044         sink_.fill (oldfill);
00045         bytecount = 23;
00046     }
00047     return bytecount;
00048 }

void ASSA::Logger_Impl::disable_all_groups ( void   )  [inline]

Definition at line 161 of file Logger_Impl.h.

References m_groups.

Referenced by ASSA::Logger::disable_all_groups().

00161 { m_groups = 0;    }

void ASSA::Logger_Impl::disable_group ( Group  g_  )  [inline]

Definition at line 155 of file Logger_Impl.h.

References m_groups.

Referenced by ASSA::Logger::disable_group().

00155 { m_groups &= ~g_; }

void ASSA::Logger_Impl::disable_groups ( u_long  g_  )  [inline]

Definition at line 158 of file Logger_Impl.h.

References m_groups.

Referenced by ASSA::Logger::disable_groups().

00158 { m_groups &= ~g_; }

void ASSA::Logger_Impl::disable_timestamp ( void   )  [inline]

Definition at line 166 of file Logger_Impl.h.

References m_tmflg.

Referenced by ASSA::Logger::disable_timestamp().

00166 { m_tmflg = false; }

void ASSA::Logger_Impl::enable_all_groups ( void   )  [inline]

Definition at line 160 of file Logger_Impl.h.

References ASSA::ALL, and m_groups.

Referenced by ASSA::Logger::enable_all_groups().

00160 { m_groups = ASSA::ALL;  }

void ASSA::Logger_Impl::enable_group ( Group  g_  )  [inline]

Definition at line 154 of file Logger_Impl.h.

References m_groups.

Referenced by ASSA::Logger::enable_group().

00154 { m_groups |= g_;  }

void ASSA::Logger_Impl::enable_groups ( u_long  g_  )  [inline]

Definition at line 157 of file Logger_Impl.h.

References m_groups.

Referenced by ASSA::Logger::enable_groups().

00157 { m_groups |= g_;  }

void ASSA::Logger_Impl::enable_timestamp ( void   )  [inline]

Definition at line 165 of file Logger_Impl.h.

References m_tmflg.

Referenced by ASSA::Logger::enable_timestamp().

00165 { m_tmflg = true;  }

char * Logger_Impl::format_msg ( size_t  expected_sz_,
const char *  fmt_,
va_list  vap_,
bool &  release_ 
) [protected]

Format and put the message in the buffer.

If expected size is smaller then LOGGER_MAXLINE, formatted message is written to the static buffer and release_ is set to false. Otherwise, this function allocates a buffer on the heap big enough to hold the message and set release_ to true. In this case caller is responsible for releasing the memory by calling delete [].

Parameters:
expected_sz_ Expected size of the formatted message
fmt_ printf()-like format string
vap_ variable argument parameters list
release_ [OUT] if true, caller is responsible for memory deallocation.
Returns:
Pointer to the formatted message buffer. If formatting failed, NULL is returned.

Definition at line 84 of file Logger_Impl.cpp.

References ASSA::flush(), LOGGER_MAXLINE, and m_msgbuf.

Referenced by ASSA::StdOutLogger::log_msg(), ASSA::RemoteLogger::log_msg(), and ASSA::FileLogger::log_msg().

00088 {
00089     char* msg = m_msgbuf;       // Use internal buffer
00090     int ret = 0;
00091 
00092     release_ = false;
00093     expected_sz_++;             // Expected size includes '\0'
00094 
00095     if (expected_sz_ >= LOGGER_MAXLINE) { // Allocate temporary buffer
00096         msg = new char [expected_sz_];
00097         release_ = true;
00098     }
00099 
00100     ret = ::vsnprintf (msg, expected_sz_, fmt_, vap_);
00101 #if NEVER
00102     if (ret < 0) {
00103         std::cout << "Logger_Impl: format_mg(expected_sz=" << expected_sz_
00104                   << ")=-1 failed! errno=" << errno << " ("
00105                   << strerror(errno) << "\n" << std::flush;
00106     }
00107 #endif
00108 
00109     return (ret < 0 ? NULL : msg);
00110 }

u_short ASSA::Logger_Impl::get_indent_step ( void   )  const [inline]

Definition at line 171 of file Logger_Impl.h.

References m_indent_step.

00171 { return m_indent_step;  }

bool ASSA::Logger_Impl::group_enabled ( Group  g_  )  const [inline]
u_short Logger_Impl::indent_func_name ( ostream &  sink_,
const string &  funcname_,
size_t  indent_level_,
marker_t  type_ 
) [protected, virtual]

Definition at line 52 of file Logger_Impl.cpp.

References ASSA::FUNC_ENTRY, ASSA::FUNC_EXIT, ASSA::FUNC_MSG, and m_indent_step.

Referenced by ASSA::StdOutLogger::log_func(), ASSA::RemoteLogger::log_func(), ASSA::FileLogger::log_func(), ASSA::StdOutLogger::log_msg(), ASSA::RemoteLogger::log_msg(), and ASSA::FileLogger::log_msg().

00056 {
00057     u_short bytecount = 0;
00058 
00059     if (func_name_.size ()) {
00060         u_int i = 1; 
00061         while (i < indent_level_) { 
00062             sink_ << '|';
00063             for (u_short j = 0; j < m_indent_step-1; j++) {
00064                 sink_ << ' ';
00065             }
00066             i++;
00067         }
00068         if (type_ == FUNC_ENTRY) {
00069             sink_ << '/' << func_name_ << "  ";
00070         }
00071         else if (type_ == FUNC_EXIT) {
00072             sink_ << '\\' << func_name_ << "  ";
00073         }
00074         else if (type_ == FUNC_MSG) {
00075             sink_ << '[' << func_name_ << "] ";
00076         }
00077         bytecount += indent_level_ * m_indent_step + func_name_.size () + 3;
00078     }
00079     return bytecount;
00080 }

virtual int ASSA::Logger_Impl::log_close ( void   )  [pure virtual]
virtual int ASSA::Logger_Impl::log_func ( Group  g_,
size_t  indent_level_,
const string &  func_name_,
marker_t  type_ 
) [pure virtual]
virtual int ASSA::Logger_Impl::log_msg ( Group  g_,
size_t  indent_level_,
const string &  func_name_,
size_t  expected_sz_,
const char *  fmt_,
va_list   
) [pure virtual]
int ASSA::Logger_Impl::log_open ( const char *  appname_,
const char *  logfname_,
u_long  groups_,
u_long  maxsize_,
Reactor reactor_ 
) [inline, virtual]

Open connection with Log Server.

Reimplemented in ASSA::RemoteLogger.

Definition at line 281 of file Logger_Impl.h.

00286 {
00287     errno = ENOSYS;
00288     return -1;
00289 }

int ASSA::Logger_Impl::log_open ( const char *  logfname_,
u_long  groups_,
u_long  maxsize_ 
) [inline, virtual]

Open File Logger.

Reimplemented in ASSA::FileLogger.

Definition at line 271 of file Logger_Impl.h.

00274 {
00275     errno = ENOSYS;
00276     return -1;
00277 }

int ASSA::Logger_Impl::log_open ( u_long  groups_  )  [inline, virtual]

Open StdErr Logger.

Reimplemented in ASSA::StdOutLogger.

Definition at line 263 of file Logger_Impl.h.

Referenced by ASSA::Logger::log_open().

00264 {
00265     errno = ENOSYS;
00266     return -1;
00267 }

virtual void ASSA::Logger_Impl::log_resync ( void   )  [inline, virtual]

Reimplemented in ASSA::FileLogger, ASSA::RemoteLogger, and ASSA::StdOutLogger.

Definition at line 189 of file Logger_Impl.h.

Referenced by ASSA::Logger::log_resync().

00189 { /* empty */ }

void ASSA::Logger_Impl::set_indent_step ( u_short  step_  )  [inline]

Definition at line 170 of file Logger_Impl.h.

References m_indent_step.

00170 { m_indent_step = step_; }

void ASSA::Logger_Impl::set_timezone ( int  zone_  )  [inline]

Definition at line 168 of file Logger_Impl.h.

References m_tz.

Referenced by ASSA::Logger::set_timezone().

00168 { m_tz = zone_;    }

bool ASSA::Logger_Impl::timestamp_enabled ( void   )  const [inline]

Definition at line 167 of file Logger_Impl.h.

References m_tmflg.

Referenced by add_timestamp(), and ASSA::Logger::timestamp_enabled().

00167 { return m_tmflg;  }


Member Data Documentation

const unsigned int ASSA::Logger_Impl::LOGGER_MAXLINE = 6660 [static]

Maximum length of the formatted message.

The size is selected based on the maximum number of bytes transmitted through Socketbuf which is 1416. This is at most the bytes dumped with MemDump - (1416/16 + 2) * 74 = 6660. See MemDump.cpp comments for details.

Definition at line 148 of file Logger_Impl.h.

Referenced by format_msg().

Indentation step.

Definition at line 235 of file Logger_Impl.h.

Referenced by ASSA::FileLogger::dump(), get_indent_step(), indent_func_name(), and set_indent_step().

string ASSA::Logger_Impl::m_logfname [protected]
char Logger_Impl::m_msgbuf [static, protected]

Static buffer for formatted message.

Definition at line 232 of file Logger_Impl.h.

Referenced by format_msg().

bool ASSA::Logger_Impl::m_tmflg [protected]

Timestamp on/off flag.

Definition at line 244 of file Logger_Impl.h.

Referenced by disable_timestamp(), ASSA::FileLogger::dump(), enable_timestamp(), and timestamp_enabled().

int ASSA::Logger_Impl::m_tz [protected]

Timezone: 0-GMT, 1-Local.

Definition at line 247 of file Logger_Impl.h.

Referenced by add_timestamp(), and set_timezone().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Dec 21 14:50:41 2009 for libassa by  doxygen 1.6.1