libassa 3.5.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ASSA::Logger_Impl Class Referenceabstract

#include <Logger_Impl.h>

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

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_)
 
charformat_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 141 of file Logger_Impl.h.

Constructor & Destructor Documentation

◆ Logger_Impl()

ASSA::Logger_Impl::Logger_Impl ( )
inline

Definition at line 252 of file Logger_Impl.h.

254 : m_indent_step (1),
255 m_groups (0),
256 m_tmflg (false),
257 m_tz (1)
258{
259 /* no-op */
260}
u_short m_indent_step
Indentation step.
int m_tz
Timezone: 0-GMT, 1-Local.
u_long m_groups
Enabled groups.
bool m_tmflg
Timestamp on/off flag.

◆ ~Logger_Impl()

virtual ASSA::Logger_Impl::~Logger_Impl ( )
inlinevirtual

Definition at line 153 of file Logger_Impl.h.

153{ /* empty */ }

Member Function Documentation

◆ add_timestamp()

u_short Logger_Impl::add_timestamp ( ostream &  sink_)
protectedvirtual

Definition at line 34 of file Logger_Impl.cpp.

36{
37 /*--- 'DD/MM/CC HH:MM:SS.MMMM ' - 23 chars ---*/
39
40 if (timestamp_enabled ()) {
42 tv.tz (m_tz);
43 sink_ << tv.fmtString ("%m/%d/%Y %H:%M:%S") << '.';
44 char oldfill = sink_.fill('0');
45 sink_ << std::setw (3) << (tv.msec () % 1000000)/1000 << ' ';
46 sink_.fill (oldfill);
47 bytecount = 23;
48 }
49 return bytecount;
50}
unsigned short u_short
Definition Logger_Impl.h:39
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
bool timestamp_enabled(void) const
static TimeVal gettimeofday()
Shields off underlying OS differences in getting current time.
Definition TimeVal.cpp:44

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

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

◆ disable_all_groups()

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

Definition at line 162 of file Logger_Impl.h.

162{ m_groups = 0; }

References m_groups.

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

◆ disable_group()

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

Definition at line 156 of file Logger_Impl.h.

156{ m_groups &= ~g_; }

References m_groups.

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

◆ disable_groups()

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

Definition at line 159 of file Logger_Impl.h.

159{ m_groups &= ~g_; }

References m_groups.

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

◆ disable_timestamp()

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

Definition at line 167 of file Logger_Impl.h.

167{ m_tmflg = false; }

References m_tmflg.

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

◆ enable_all_groups()

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

Definition at line 161 of file Logger_Impl.h.

161{ m_groups = ASSA::ALL; }
@ ALL
All messages: library + application
Definition LogMask.h:62

References ASSA::ALL, and m_groups.

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

◆ enable_group()

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

Definition at line 155 of file Logger_Impl.h.

155{ m_groups |= g_; }

References m_groups.

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

◆ enable_groups()

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

Definition at line 158 of file Logger_Impl.h.

158{ m_groups |= g_; }

References m_groups.

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

◆ enable_timestamp()

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

Definition at line 166 of file Logger_Impl.h.

166{ m_tmflg = true; }

References m_tmflg.

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

◆ format_msg()

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 85 of file Logger_Impl.cpp.

90{
91 char* msg = m_msgbuf; // Use internal buffer
92 int ret = 0;
93
94 release_ = false;
95 expected_sz_++; // Expected size includes '\0'
96
97 if (expected_sz_ >= LOGGER_MAXLINE) { // Allocate temporary buffer
98 msg = new char [expected_sz_];
99 release_ = true;
100 }
101
103#if NEVER
104 if (ret < 0) {
105 std::cout << "Logger_Impl: format_mg(expected_sz=" << expected_sz_
106 << ")=-1 failed! errno=" << errno << " ("
107 << strerror(errno) << "\n" << std::flush;
108 }
109#endif
110
111 return (ret < 0 ? NULL : msg);
112}
static char m_msgbuf[LOGGER_MAXLINE]
Static buffer for formatted message.
static const unsigned int LOGGER_MAXLINE
Maximum length of the formatted message.

References LOGGER_MAXLINE, and m_msgbuf.

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

◆ get_indent_step()

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

Definition at line 172 of file Logger_Impl.h.

172{ return m_indent_step; }

References m_indent_step.

◆ group_enabled()

bool ASSA::Logger_Impl::group_enabled ( Group  g_) const
inline

◆ indent_func_name()

u_short Logger_Impl::indent_func_name ( ostream &  sink_,
const string &  funcname_,
size_t  indent_level_,
marker_t  type_ 
)
protectedvirtual

Definition at line 53 of file Logger_Impl.cpp.

58{
60
61 if (func_name_.size ()) {
62 u_int i = 1;
63 while (i < indent_level_) {
64 sink_ << '|';
65 for (u_short j = 0; j < m_indent_step-1; j++) {
66 sink_ << ' ';
67 }
68 i++;
69 }
70 if (type_ == FUNC_ENTRY) {
71 sink_ << '/' << func_name_ << " ";
72 }
73 else if (type_ == FUNC_EXIT) {
74 sink_ << '\\' << func_name_ << " ";
75 }
76 else if (type_ == FUNC_MSG) {
77 sink_ << '[' << func_name_ << "] ";
78 }
80 }
81 return bytecount;
82}
@ FUNC_ENTRY
Definition LogMask.h:69
@ FUNC_MSG
Definition LogMask.h:68
@ FUNC_EXIT
Definition LogMask.h:70

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

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

◆ log_close()

virtual int ASSA::Logger_Impl::log_close ( void  )
pure virtual

◆ log_func()

virtual int ASSA::Logger_Impl::log_func ( Group  g_,
size_t  indent_level_,
const string &  func_name_,
marker_t  type_ 
)
pure virtual

◆ log_msg()

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

◆ log_open() [1/3]

int ASSA::Logger_Impl::log_open ( const char appname_,
const char logfname_,
u_long  groups_,
u_long  maxsize_,
Reactor reactor_ 
)
inlinevirtual

Open connection with Log Server.

Reimplemented in ASSA::RemoteLogger.

Definition at line 281 of file Logger_Impl.h.

287{
288 errno = ENOSYS;
289 return -1;
290}

◆ log_open() [2/3]

int ASSA::Logger_Impl::log_open ( const char logfname_,
u_long  groups_,
u_long  maxsize_ 
)
inlinevirtual

Open File Logger.

Reimplemented in ASSA::FileLogger.

Definition at line 271 of file Logger_Impl.h.

275{
276 errno = ENOSYS;
277 return -1;
278}

◆ log_open() [3/3]

int ASSA::Logger_Impl::log_open ( u_long  groups_)
inlinevirtual

Open StdErr Logger.

Reimplemented in ASSA::StdOutLogger.

Definition at line 263 of file Logger_Impl.h.

265{
266 errno = ENOSYS;
267 return -1;
268}

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

◆ log_resync()

virtual void ASSA::Logger_Impl::log_resync ( void  )
inlinevirtual

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

Definition at line 190 of file Logger_Impl.h.

190{ /* empty */ }

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

◆ set_indent_step()

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

Definition at line 171 of file Logger_Impl.h.

171{ m_indent_step = step_; }

References m_indent_step.

◆ set_timezone()

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

Definition at line 169 of file Logger_Impl.h.

169{ m_tz = zone_; }

References m_tz.

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

◆ timestamp_enabled()

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

Definition at line 168 of file Logger_Impl.h.

168{ return m_tmflg; }

References m_tmflg.

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

Member Data Documentation

◆ LOGGER_MAXLINE

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 149 of file Logger_Impl.h.

Referenced by format_msg().

◆ m_groups

u_long ASSA::Logger_Impl::m_groups
protected

◆ m_indent_step

u_short ASSA::Logger_Impl::m_indent_step
protected

Indentation step.

Definition at line 236 of file Logger_Impl.h.

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

◆ m_logfname

string ASSA::Logger_Impl::m_logfname
protected

◆ m_msgbuf

char Logger_Impl::m_msgbuf
staticprotected

Static buffer for formatted message.

Definition at line 233 of file Logger_Impl.h.

Referenced by format_msg().

◆ m_tmflg

bool ASSA::Logger_Impl::m_tmflg
protected

Timestamp on/off flag.

Definition at line 245 of file Logger_Impl.h.

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

◆ m_tz

int ASSA::Logger_Impl::m_tz
protected

Timezone: 0-GMT, 1-Local.

Definition at line 248 of file Logger_Impl.h.

Referenced by add_timestamp(), and set_timezone().


The documentation for this class was generated from the following files: