Instrument Neutral Distributed Interface INDI  1.5.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
INDI::Logger Class Reference

The Logger class is a simple logger to log messages to file and INDI clients. This is the implementation of a simple logger in C++. It is implemented as a Singleton, so it can be easily called through two DEBUG macros. It is Pthread-safe. It allows to log on both file and screen, and to specify a verbosity threshold for both of them. More...

#include <indilogger.h>

Inheritance diagram for INDI::Logger:

Classes

struct  switchinit
 

Public Types

typedef loggerConf_ loggerConf
 

Public Member Functions

int addDebugLevel (const char *debugLevelName, const char *LoggingLevelName)
 Adds a new debugging level to the driver. More...
 
void print (const char *devicename, const unsigned int verbosityLevel, const std::string &sourceFile, const int codeLine, const char *message,...)
 
void configure (const std::string &outputFile, const loggerConf configuration, const int fileVerbosityLevel, const int screenVerbosityLevel)
 Method to configure the logger. Called by the DEBUG_CONF() macro. To make implementation easier, the old stream is always closed. Then, in case, it is open again in append mode. More...
 

Static Public Member Functions

static std::string getLogFile ()
 
static loggerConf_ getConfiguration ()
 
static LoggergetInstance ()
 Method to get a reference to the object (i.e., Singleton) It is a static method. More...
 
static bool saveConfigItems (FILE *fp)
 
static bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
 
static bool initProperties (INDI::DefaultDevice *device)
 
static bool updateProperties (bool enable)
 
static unsigned int rank (unsigned int l)
 Method used to print message called by the DEBUG() macro. More...
 

Static Public Attributes

static const unsigned int defaultlevel = DBG_ERROR | DBG_WARNING | DBG_SESSION
 
static const unsigned int nlevels = 8
 
static struct switchinit LoggingLevelSInit [nlevels]
 
static ISwitch LoggingLevelS [nlevels]
 
static ISwitchVectorProperty LoggingLevelSP
 
static ISwitch ConfigurationS [2]
 
static ISwitchVectorProperty ConfigurationSP
 
static const loggerConf file_on = L_nofile_
 
static const loggerConf file_off = L_file_
 
static const loggerConf screen_on = L_noscreen_
 
static const loggerConf screen_off = L_screen_
 
static unsigned int customLevel = 4
 
static unsigned int nDevices = 0
 
static struct switchinit DebugLevelSInit [nlevels]
 
static ISwitch DebugLevelS [nlevels]
 
static ISwitchVectorProperty DebugLevelSP
 
static char Tags [nlevels][MAXINDINAME]
 

Detailed Description

The Logger class is a simple logger to log messages to file and INDI clients. This is the implementation of a simple logger in C++. It is implemented as a Singleton, so it can be easily called through two DEBUG macros. It is Pthread-safe. It allows to log on both file and screen, and to specify a verbosity threshold for both of them.

Note
Use DEBUGF macro if you have a variable list message. e.g. DEBUGF(INDI::Logger::DBG_SESSION, "Hello %s!", "There")

The default active debug levels are Error, Warning, and Session. Driver Debug can be enabled by the client.

To add a new debug level, call addDebugLevel(). You can add an additional 4 custom debug/logging levels.

Check INDI Tutorial two for an example simple implementation.

Definition at line 35 of file indilogger.cpp.

Member Typedef Documentation

typedef loggerConf_ INDI::Logger::loggerConf

Definition at line 190 of file indilogger.h.

Member Enumeration Documentation

Enumerator
DBG_ERROR 
DBG_WARNING 
DBG_SESSION 
DBG_DEBUG 
DBG_EXTRA_1 
DBG_EXTRA_2 
DBG_EXTRA_3 
DBG_EXTRA_4 

Definition at line 163 of file indilogger.h.

Member Function Documentation

int INDI::Logger::addDebugLevel ( const char *  debugLevelName,
const char *  LoggingLevelName 
)

Adds a new debugging level to the driver.

Parameters
debugLevelNameThe descriptive debug level defined to the client. e.g. Scope Status
LoggingLevelNamethe short logging level recorded in the logfile. e.g. SCOPE
Returns
bitmask of the new debugging level to be used for any subsequent calls to DEBUG and DEBUGF to record events to this debug level.
Examples:
simplescope.cpp.

Definition at line 93 of file indilogger.cpp.

void INDI::Logger::configure ( const std::string &  outputFile,
const loggerConf  configuration,
const int  fileVerbosityLevel,
const int  screenVerbosityLevel 
)

Method to configure the logger. Called by the DEBUG_CONF() macro. To make implementation easier, the old stream is always closed. Then, in case, it is open again in append mode.

Parameters
outputFileof the file used for logging
configuration(i.e., log on file and on screen on or off)
fileVerbosityLevelthreshold for file
screenVerbosityLevelthreshold for screen

Definition at line 304 of file indilogger.cpp.

static loggerConf_ INDI::Logger::getConfiguration ( )
inlinestatic

Definition at line 199 of file indilogger.h.

Logger & INDI::Logger::getInstance ( )
static

Method to get a reference to the object (i.e., Singleton) It is a static method.

Returns
Reference to the object.
Examples:
simplescope.cpp.

Definition at line 360 of file indilogger.cpp.

static std::string INDI::Logger::getLogFile ( )
inlinestatic

Definition at line 198 of file indilogger.h.

bool INDI::Logger::initProperties ( INDI::DefaultDevice device)
static

Definition at line 106 of file indilogger.cpp.

bool INDI::Logger::ISNewSwitch ( const char *  dev,
const char *  name,
ISState states,
char *  names[],
int  n 
)
static

Definition at line 166 of file indilogger.cpp.

void INDI::Logger::print ( const char *  devicename,
const unsigned int  verbosityLevel,
const std::string &  sourceFile,
const int  codeLine,
const char *  message,
  ... 
)

Definition at line 393 of file indilogger.cpp.

unsigned int INDI::Logger::rank ( unsigned int  l)
static

Method used to print message called by the DEBUG() macro.

Parameters
iwhich debugging to query its rank. The lower the rank, the more priority it is.
Returns
rank of debugging level requested.

Definition at line 369 of file indilogger.cpp.

bool INDI::Logger::saveConfigItems ( FILE *  fp)
static

Definition at line 157 of file indilogger.cpp.

bool INDI::Logger::updateProperties ( bool  enable)
static

Definition at line 134 of file indilogger.cpp.

Member Data Documentation

ISwitch INDI::Logger::ConfigurationS
static

Definition at line 188 of file indilogger.h.

ISwitchVectorProperty INDI::Logger::ConfigurationSP
static

Definition at line 189 of file indilogger.h.

unsigned int INDI::Logger::customLevel = 4
static

Definition at line 195 of file indilogger.h.

ISwitch INDI::Logger::DebugLevelS
static

Definition at line 238 of file indilogger.h.

struct switchinit INDI::Logger::DebugLevelSInit[nlevels]
static

Definition at line 237 of file indilogger.h.

ISwitchVectorProperty INDI::Logger::DebugLevelSP
static

Definition at line 239 of file indilogger.h.

const unsigned int INDI::Logger::defaultlevel = DBG_ERROR | DBG_WARNING | DBG_SESSION
static

Definition at line 183 of file indilogger.h.

const loggerConf INDI::Logger::file_off = L_file_
static

Definition at line 192 of file indilogger.h.

const loggerConf INDI::Logger::file_on = L_nofile_
static

Definition at line 191 of file indilogger.h.

ISwitch INDI::Logger::LoggingLevelS
static

Definition at line 186 of file indilogger.h.

struct switchinit INDI::Logger::LoggingLevelSInit[nlevels]
static

Definition at line 185 of file indilogger.h.

ISwitchVectorProperty INDI::Logger::LoggingLevelSP
static

Definition at line 187 of file indilogger.h.

unsigned int INDI::Logger::nDevices = 0
static

Definition at line 196 of file indilogger.h.

const unsigned int INDI::Logger::nlevels = 8
static

Definition at line 184 of file indilogger.h.

const loggerConf INDI::Logger::screen_off = L_screen_
static

Definition at line 194 of file indilogger.h.

const loggerConf INDI::Logger::screen_on = L_noscreen_
static

Definition at line 193 of file indilogger.h.

char INDI::Logger::Tags
static
Initial value:
= { "ERROR", "WARNING", "INFO", "DEBUG",
"DBG_EXTRA_1", "DBG_EXTRA_2", "DBG_EXTRA_3", "DBG_EXTRA_4" }

Definition at line 243 of file indilogger.h.


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