The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SWLog Class Reference

#include <swlog.h>

+ Collaboration diagram for SWLog:

Public Member Functions

char getLogLevel () const
 
void logDebug (const char *fmt,...) const
 
void logError (const char *fmt,...) const
 
void logInformation (const char *fmt,...) const
 
virtual void logMessage (const char *message, int level) const
 
virtual void logTimedInformation (const char *fmt,...) const
 
void logWarning (const char *fmt,...) const
 
void setLogLevel (char level)
 
 SWLog ()
 
virtual ~SWLog ()
 

Static Public Member Functions

static SWLoggetSystemLog ()
 
static void setSystemLog (SWLog *newLogger)
 

Static Public Attributes

static const char LOG_DEBUG = 5
 
static const char LOG_ERROR = 1
 
static const char LOG_INFO = 3
 
static const char LOG_TIMEDINFO = 4
 
static const char LOG_WARN = 2
 

Protected Attributes

char logLevel
 

Static Protected Attributes

static SWLogsystemLog = 0
 

Detailed Description

Definition at line 34 of file swlog.h.

Constructor & Destructor Documentation

SWLog::SWLog ( )
inline

Definition at line 51 of file swlog.h.

51 { logLevel = 1; /*default to show only errors*/}
char logLevel
Definition: swlog.h:37
virtual SWLog::~SWLog ( )
inlinevirtual

Definition at line 52 of file swlog.h.

52 {};

Member Function Documentation

char SWLog::getLogLevel ( ) const
inline

Definition at line 55 of file swlog.h.

55 { return logLevel; }
char logLevel
Definition: swlog.h:37
SWLog * SWLog::getSystemLog ( )
static

Definition at line 53 of file swlog.cpp.

53  {
54  static class __staticSystemLog {
55  SWLog **clear;
56  public:
57  __staticSystemLog(SWLog **clear) { this->clear = clear; }
58  ~__staticSystemLog() { delete *clear; *clear = 0; }
59  } _staticSystemLog(&SWLog::systemLog);
60 
61  if (!systemLog)
62  systemLog = new SWLog();
63 
64  return systemLog;
65 }
SWLog()
Definition: swlog.h:51
Definition: swlog.h:34
static SWLog * systemLog
Definition: swlog.h:38
void SWLog::logDebug ( const char *  fmt,
  ... 
) const

Definition at line 132 of file swlog.cpp.

132  {
133  va_list argptr;
134 
135  if (logLevel >= LOG_DEBUG) {
136  SWBuf msg;
137  va_start(argptr, fmt);
138  msg.setFormattedVA(fmt, argptr);
139  va_end(argptr);
140  logMessage(msg, LOG_DEBUG);
141  }
142 }
virtual void logMessage(const char *message, int level) const
Definition: swlog.cpp:144
Definition: swbuf.h:47
SWBuf & setFormattedVA(const char *format, va_list argptr)
Definition: swbuf.cpp:61
char logLevel
Definition: swlog.h:37
static const char LOG_DEBUG
Definition: swlog.h:46
void SWLog::logError ( const char *  fmt,
  ... 
) const

Definition at line 87 of file swlog.cpp.

87  {
88  va_list argptr;
89 
90  if (logLevel) {
91  SWBuf msg;
92  va_start(argptr, fmt);
93  msg.setFormattedVA(fmt, argptr);
94  va_end(argptr);
95  logMessage(msg, LOG_ERROR);
96  }
97 }
virtual void logMessage(const char *message, int level) const
Definition: swlog.cpp:144
Definition: swbuf.h:47
SWBuf & setFormattedVA(const char *format, va_list argptr)
Definition: swbuf.cpp:61
char logLevel
Definition: swlog.h:37
static const char LOG_ERROR
Definition: swlog.h:42
void SWLog::logInformation ( const char *  fmt,
  ... 
) const

Definition at line 100 of file swlog.cpp.

100  {
101  va_list argptr;
102 
103  if (logLevel >= LOG_INFO) {
104  SWBuf msg;
105  va_start(argptr, fmt);
106  msg.setFormattedVA(fmt, argptr);
107  va_end(argptr);
108  logMessage(msg, LOG_INFO);
109  }
110 }
virtual void logMessage(const char *message, int level) const
Definition: swlog.cpp:144
Definition: swbuf.h:47
SWBuf & setFormattedVA(const char *format, va_list argptr)
Definition: swbuf.cpp:61
char logLevel
Definition: swlog.h:37
static const char LOG_INFO
Definition: swlog.h:44
void SWLog::logMessage ( const char *  message,
int  level 
) const
virtual

Definition at line 144 of file swlog.cpp.

144  {
145  std::cerr << message;
146  std::cerr << std::endl;
147 }
void SWLog::logTimedInformation ( const char *  fmt,
  ... 
) const
virtual

Definition at line 113 of file swlog.cpp.

113  {
114  va_list argptr;
115 
116  if (logLevel >= LOG_TIMEDINFO) {
117  const char *fmtStr = fmt;
118  SWBuf msg;
119 #ifdef USECXX11TIME
120  SWBuf msgTS;
121  msgTS.setFormatted("[%.5f] %s", duration_cast<duration<double>>(high_resolution_clock::now() - baseTime).count(), fmt);
122  fmtStr = msgTS.c_str();
123 #endif
124  va_start(argptr, fmt);
125  msg.setFormattedVA(fmtStr, argptr);
126  va_end(argptr);
128  }
129 }
virtual void logMessage(const char *message, int level) const
Definition: swlog.cpp:144
Definition: swbuf.h:47
SWBuf & setFormattedVA(const char *format, va_list argptr)
Definition: swbuf.cpp:61
char logLevel
Definition: swlog.h:37
const char * c_str() const
Definition: swbuf.h:158
static long now
Definition: ftpparse.c:48
SWBuf & setFormatted(const char *format,...)
Definition: swbuf.cpp:50
static const char LOG_TIMEDINFO
Definition: swlog.h:45
void SWLog::logWarning ( const char *  fmt,
  ... 
) const

Definition at line 74 of file swlog.cpp.

74  {
75  va_list argptr;
76 
77  if (logLevel >= LOG_WARN) {
78  SWBuf msg;
79  va_start(argptr, fmt);
80  msg.setFormattedVA(fmt, argptr);
81  va_end(argptr);
82  logMessage(msg, LOG_WARN);
83  }
84 }
virtual void logMessage(const char *message, int level) const
Definition: swlog.cpp:144
Definition: swbuf.h:47
SWBuf & setFormattedVA(const char *format, va_list argptr)
Definition: swbuf.cpp:61
char logLevel
Definition: swlog.h:37
static const char LOG_WARN
Definition: swlog.h:43
void SWLog::setLogLevel ( char  level)
inline

Definition at line 54 of file swlog.h.

54 { logLevel = level; }
char logLevel
Definition: swlog.h:37
void SWLog::setSystemLog ( SWLog newLogger)
static

Definition at line 68 of file swlog.cpp.

68  {
69  delete getSystemLog();
70  systemLog = newLog;
71 }
static SWLog * getSystemLog()
Definition: swlog.cpp:53
static SWLog * systemLog
Definition: swlog.h:38

Member Data Documentation

const char SWLog::LOG_DEBUG = 5
static

Definition at line 46 of file swlog.h.

const char SWLog::LOG_ERROR = 1
static

Definition at line 42 of file swlog.h.

const char SWLog::LOG_INFO = 3
static

Definition at line 44 of file swlog.h.

const char SWLog::LOG_TIMEDINFO = 4
static

Definition at line 45 of file swlog.h.

const char SWLog::LOG_WARN = 2
static

Definition at line 43 of file swlog.h.

char SWLog::logLevel
protected

Definition at line 37 of file swlog.h.

SWORD_NAMESPACE_START SWLog * SWLog::systemLog = 0
staticprotected

Definition at line 38 of file swlog.h.


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