CPN
Computational Process Networks
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Logger Class Reference

Logger object that is used for forwarding log messages. More...

#include <Logger.h>

+ Inheritance diagram for Logger:
+ Collaboration diagram for Logger:

Public Types

enum  {
  ERROR = 100, WARNING = 75, INFO = 50, DEBUG = 25,
  TRACE = 0
}
 

Public Member Functions

 Logger ()
 
 Logger (int dfltlvl)
 
 Logger (LoggerOutput *lo, int dfltlvl)
 
 Logger (LoggerOutput *lo, int dfltlevel, const std::string &nm)
 
virtual ~Logger ()
 
int LogLevel () const
 
int LogLevel (int level)
 
int DefaultLevel () const
 
int DefaultLevel (int level)
 
int Adjust () const
 
int Adjust (int a)
 
const std::string & Name () const
 
const std::string & Name (const std::string &nm)
 
LoggerOutputOutput ()
 
LoggerOutputOutput (LoggerOutput *output)
 
virtual void Log (int level, const std::string &msg)
 Log a message to this outputer. More...
 
void Log (const std::string &msg)
 
void Logf (int level, const char *fmt,...)
 
void vLogf (int level, const char *fmt, va_list ap)
 
void Logf (const char *fmt,...)
 
void Error (const char *fmt,...)
 
void Warn (const char *fmt,...)
 
void Info (const char *fmt,...)
 
void Debug (const char *fmt,...)
 
void Trace (const char *fmt,...)
 

Protected Member Functions

 Logger (const Logger &)
 
Loggeroperator= (const Logger &)
 

Private Attributes

Sync::ReentrantLock lock
 
LoggerOutputlogout
 
int loglevel
 
int defaultlevel
 
int adjust
 
std::string name
 

Detailed Description

Logger object that is used for forwarding log messages.

Definition at line 57 of file Logger.h.

Member Enumeration Documentation

anonymous enum
Enumerator
ERROR 
WARNING 
INFO 
DEBUG 
TRACE 

Definition at line 59 of file Logger.h.

59  {
60  ERROR = 100,
61  WARNING = 75,
62  INFO = 50,
63  DEBUG = 25,
64  TRACE = 0
65  };

Constructor & Destructor Documentation

Logger::Logger ( )

Definition at line 34 of file Logger.cc.

36 {}
int defaultlevel
Definition: Logger.h:110
LoggerOutput * logout
Definition: Logger.h:108
int loglevel
Definition: Logger.h:109
int adjust
Definition: Logger.h:111
Logger::Logger ( int  dfltlvl)

Definition at line 38 of file Logger.cc.

39  : logout(0), loglevel(WARNING), defaultlevel(dfltlvl), adjust(0)
40 {}
int defaultlevel
Definition: Logger.h:110
LoggerOutput * logout
Definition: Logger.h:108
int loglevel
Definition: Logger.h:109
int adjust
Definition: Logger.h:111
Logger::Logger ( LoggerOutput lo,
int  dfltlvl 
)

Definition at line 44 of file Logger.cc.

References ASSERT, LoggerOutput::LogLevel(), loglevel, and logout.

45  : logout(lo), loglevel(WARNING), defaultlevel(dfltlvl), adjust(0)
46 {
47  ASSERT(logout);
49 }
virtual int LogLevel() const =0
int defaultlevel
Definition: Logger.h:110
LoggerOutput * logout
Definition: Logger.h:108
int loglevel
Definition: Logger.h:109
int adjust
Definition: Logger.h:111
#define ASSERT(exp,...)

+ Here is the call graph for this function:

Logger::Logger ( LoggerOutput lo,
int  dfltlevel,
const std::string &  nm 
)

Definition at line 51 of file Logger.cc.

References ASSERT, LoggerOutput::LogLevel(), loglevel, and logout.

52  : logout(lo), loglevel(WARNING), defaultlevel(dfltlevel), name(nm)
53 {
54  ASSERT(logout);
56 }
std::string name
Definition: Logger.h:112
virtual int LogLevel() const =0
int defaultlevel
Definition: Logger.h:110
LoggerOutput * logout
Definition: Logger.h:108
int loglevel
Definition: Logger.h:109
#define ASSERT(exp,...)

+ Here is the call graph for this function:

Logger::~Logger ( )
virtual

Definition at line 42 of file Logger.cc.

42 {}
Logger::Logger ( const Logger )
protected

Member Function Documentation

int Logger::Adjust ( ) const

Definition at line 78 of file Logger.cc.

References adjust, and lock.

78  {
80  return adjust;
81 }
Sync::ReentrantLock lock
Definition: Logger.h:107
int adjust
Definition: Logger.h:111
int Logger::Adjust ( int  a)

Definition at line 83 of file Logger.cc.

References adjust, and lock.

83  {
85  return adjust = a;
86 }
Sync::ReentrantLock lock
Definition: Logger.h:107
int adjust
Definition: Logger.h:111
void Logger::Debug ( const char *  fmt,
  ... 
)

Definition at line 186 of file Logger.cc.

References DEBUG, lock, loglevel, and vLogf().

Referenced by CPN::QueueBase::Detect(), CPN::RemoteQueue::FileThreadEntryPoint(), CPN::RemoteQueue::InternalCheckStatus(), CPN::RemoteQueue::Read(), CPN::RemoteQueue::SendEndOfReadPacket(), and CPN::RemoteQueue::SendEndOfWritePacket().

186  {
188  if (DEBUG < loglevel) { return; }
189  va_list ap;
190  va_start(ap, fmt);
191  vLogf(DEBUG, fmt, ap);
192  va_end(ap);
193 }
void vLogf(int level, const char *fmt, va_list ap)
Definition: Logger.cc:132
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Logger::DefaultLevel ( ) const

Definition at line 68 of file Logger.cc.

References defaultlevel, and lock.

68  {
70  return defaultlevel;
71 }
int defaultlevel
Definition: Logger.h:110
Sync::ReentrantLock lock
Definition: Logger.h:107
int Logger::DefaultLevel ( int  level)

Definition at line 73 of file Logger.cc.

References defaultlevel, and lock.

73  {
75  return defaultlevel = level;
76 }
int defaultlevel
Definition: Logger.h:110
Sync::ReentrantLock lock
Definition: Logger.h:107
void Logger::Error ( const char *  fmt,
  ... 
)

Definition at line 159 of file Logger.cc.

References ERROR, lock, loglevel, and vLogf().

Referenced by CPN::RemoteQueue::FileThreadEntryPoint(), CPN::RemoteQueue::HandleError(), CPN::RemoteQueue::InternalCheckStatus(), CPN::PseudoNode::LogState(), CPN::RemoteQueue::LogState(), CPN::ConnectionServer::LogState(), CPN::NodeBase::LogState(), CPN::QueueBase::LogState(), CPN::Kernel::LogState(), and CPN::ConnectionServer::Poll().

159  {
161  if (ERROR < loglevel) { return; }
162  va_list ap;
163  va_start(ap, fmt);
164  vLogf(ERROR, fmt, ap);
165  va_end(ap);
166 }
void vLogf(int level, const char *fmt, va_list ap)
Definition: Logger.cc:132
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Logger::Info ( const char *  fmt,
  ... 
)

Definition at line 177 of file Logger.cc.

References INFO, lock, loglevel, and vLogf().

Referenced by CPN::NodeBase::EntryPoint(), and CPN::Kernel::Kernel().

177  {
179  if (INFO < loglevel) { return; }
180  va_list ap;
181  va_start(ap, fmt);
182  vLogf(INFO, fmt, ap);
183  va_end(ap);
184 }
void vLogf(int level, const char *fmt, va_list ap)
Definition: Logger.cc:132
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Logger::Log ( int  level,
const std::string &  msg 
)
virtual

Log a message to this outputer.

Parameters
levelthe level of this message
msgthe message

Implements LoggerOutput.

Definition at line 108 of file Logger.cc.

References adjust, lock, LoggerOutput::Log(), loglevel, logout, and name.

Referenced by vLogf().

108  {
110  if (level < loglevel) { return; }
111  if (logout) { logout->Log(level + adjust, name + ":" + msg); }
112 }
std::string name
Definition: Logger.h:112
virtual void Log(int level, const std::string &msg)=0
Log a message to this outputer.
LoggerOutput * logout
Definition: Logger.h:108
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109
int adjust
Definition: Logger.h:111

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Logger::Log ( const std::string &  msg)
inline

Definition at line 89 of file Logger.h.

References defaultlevel, and Log().

Referenced by Log().

89 { Log(defaultlevel, msg); }
int defaultlevel
Definition: Logger.h:110
virtual void Log(int level, const std::string &msg)
Log a message to this outputer.
Definition: Logger.cc:108

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Logger::Logf ( int  level,
const char *  fmt,
  ... 
)

Definition at line 114 of file Logger.cc.

References lock, loglevel, and vLogf().

114  {
116  if (level < loglevel) { return; }
117  va_list ap;
118  va_start(ap, fmt);
119  vLogf(level, fmt, ap);
120  va_end(ap);
121 }
void vLogf(int level, const char *fmt, va_list ap)
Definition: Logger.cc:132
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

void Logger::Logf ( const char *  fmt,
  ... 
)

Definition at line 123 of file Logger.cc.

References defaultlevel, lock, loglevel, and vLogf().

123  {
125  if (defaultlevel < loglevel) { return; }
126  va_list ap;
127  va_start(ap, fmt);
128  vLogf(defaultlevel, fmt, ap);
129  va_end(ap);
130 }
void vLogf(int level, const char *fmt, va_list ap)
Definition: Logger.cc:132
int defaultlevel
Definition: Logger.h:110
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

int Logger::LogLevel ( ) const
virtual
Returns
the current log level

Implements LoggerOutput.

Definition at line 58 of file Logger.cc.

References lock, and loglevel.

Referenced by CPN::RemoteQueue::InternalCheckStatus(), and CPN::Kernel::Kernel().

58  {
60  return loglevel;
61 }
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the caller graph for this function:

int Logger::LogLevel ( int  level)
virtual
Parameters
levelthe new log level
Returns
the new log level

Implements LoggerOutput.

Definition at line 63 of file Logger.cc.

References lock, and loglevel.

63  {
65  return loglevel = level;
66 }
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109
const std::string & Logger::Name ( ) const

Definition at line 88 of file Logger.cc.

References lock, and name.

Referenced by CPN::NodeBase::EntryPoint(), CPN::Kernel::Kernel(), CPN::QueueBase::QueueBase(), and CPN::RemoteQueue::RemoteQueue().

88  {
90  return name;
91 }
std::string name
Definition: Logger.h:112
Sync::ReentrantLock lock
Definition: Logger.h:107

+ Here is the caller graph for this function:

const std::string & Logger::Name ( const std::string &  nm)

Definition at line 93 of file Logger.cc.

References lock, and name.

93  {
95  return name = nm;
96 }
std::string name
Definition: Logger.h:112
Sync::ReentrantLock lock
Definition: Logger.h:107
Logger& Logger::operator= ( const Logger )
protected
LoggerOutput * Logger::Output ( )

Definition at line 98 of file Logger.cc.

References lock, and logout.

Referenced by CPN::Kernel::Kernel().

98  {
100  return logout;
101 }
LoggerOutput * logout
Definition: Logger.h:108
Sync::ReentrantLock lock
Definition: Logger.h:107

+ Here is the caller graph for this function:

LoggerOutput * Logger::Output ( LoggerOutput output)

Definition at line 103 of file Logger.cc.

References lock, and logout.

103  {
105  return logout = output;
106 }
LoggerOutput * logout
Definition: Logger.h:108
Sync::ReentrantLock lock
Definition: Logger.h:107
void Logger::Trace ( const char *  fmt,
  ... 
)

Definition at line 195 of file Logger.cc.

References lock, loglevel, TRACE, and vLogf().

Referenced by CPN::RemoteQueue::RemoteQueue(), ScopeTrace::ScopeTrace(), CPN::RemoteQueue::~RemoteQueue(), and ScopeTrace::~ScopeTrace().

195  {
197  if (TRACE < loglevel) { return; }
198  va_list ap;
199  va_start(ap, fmt);
200  vLogf(TRACE, fmt, ap);
201  va_end(ap);
202 }
void vLogf(int level, const char *fmt, va_list ap)
Definition: Logger.cc:132
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Logger::vLogf ( int  level,
const char *  fmt,
va_list  ap 
)

Definition at line 132 of file Logger.cc.

References lock, Log(), and loglevel.

Referenced by Debug(), Error(), Info(), Logf(), Trace(), and Warn().

132  {
134  if (level < loglevel) { return; }
135  // This code was based on an example of how
136  // to use vsnprintf in the unix man pages.
137  std::vector<char> buff(128);
138  while (1) {
139  /* Try to print in the allocated space. */
140  va_list ap_copy;
141  va_copy(ap_copy, ap);
142  int n = vsnprintf(&buff[0], buff.size(), fmt, ap_copy);
143  /* If that worked, return the string. */
144  if (n > -1 && unsigned(n) < buff.size()) {
145  std::string ret = &buff[0];
146  Log(level, ret);
147  return;
148  }
149  /* Else try again with more space. */
150  if (n > -1) { /* glibc 2.1 */ /* precisely what is needed */
151  buff.resize(n+1);
152  }
153  else { /* glibc 2.0 */ /* twice the old size */
154  buff.resize(buff.size()*2);
155  }
156  }
157 }
virtual void Log(int level, const std::string &msg)
Log a message to this outputer.
Definition: Logger.cc:108
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Logger::Warn ( const char *  fmt,
  ... 
)

Definition at line 168 of file Logger.cc.

References lock, loglevel, vLogf(), and WARNING.

Referenced by CPN::RemoteQueue::EnqueuePacket(), CPN::Kernel::EntryPoint(), and CPN::Kernel::NodeTerminated().

168  {
170  if (WARNING < loglevel) { return; }
171  va_list ap;
172  va_start(ap, fmt);
173  vLogf(WARNING, fmt, ap);
174  va_end(ap);
175 }
void vLogf(int level, const char *fmt, va_list ap)
Definition: Logger.cc:132
Sync::ReentrantLock lock
Definition: Logger.h:107
int loglevel
Definition: Logger.h:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

int Logger::adjust
private

Definition at line 111 of file Logger.h.

Referenced by Adjust(), and Log().

int Logger::defaultlevel
private

Definition at line 110 of file Logger.h.

Referenced by DefaultLevel(), Log(), and Logf().

Sync::ReentrantLock Logger::lock
private

Definition at line 107 of file Logger.h.

Referenced by Adjust(), Debug(), DefaultLevel(), Error(), Info(), Log(), Logf(), LogLevel(), Name(), Output(), Trace(), vLogf(), and Warn().

int Logger::loglevel
private

Definition at line 109 of file Logger.h.

Referenced by Debug(), Error(), Info(), Log(), Logf(), Logger(), LogLevel(), Trace(), vLogf(), and Warn().

LoggerOutput* Logger::logout
private

Definition at line 108 of file Logger.h.

Referenced by Log(), Logger(), and Output().

std::string Logger::name
private

Definition at line 112 of file Logger.h.

Referenced by Log(), and Name().


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