Instrument Neutral Distributed Interface INDI  2.0.2
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

enum  VerbosityLevel {
  DBG_IGNORE = 0x0 , DBG_ERROR = 0x1 , DBG_WARNING = 0x2 , DBG_SESSION = 0x4 ,
  DBG_DEBUG = 0x8 , DBG_EXTRA_1 = 0x10 , DBG_EXTRA_2 = 0X20 , DBG_EXTRA_3 = 0x40 ,
  DBG_EXTRA_4 = 0x80
}
 
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 37 of file indilogger.cpp.

Member Typedef Documentation

◆ loggerConf

typedef loggerConf_ INDI::Logger::loggerConf

Definition at line 217 of file indilogger.h.

Member Enumeration Documentation

◆ VerbosityLevel

Enumerator
DBG_IGNORE 
DBG_ERROR 
DBG_WARNING 
DBG_SESSION 
DBG_DEBUG 
DBG_EXTRA_1 
DBG_EXTRA_2 
DBG_EXTRA_3 
DBG_EXTRA_4 

Definition at line 189 of file indilogger.h.

Member Function Documentation

◆ addDebugLevel()

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 72 of file indilogger.cpp.

◆ configure()

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 283 of file indilogger.cpp.

◆ getConfiguration()

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

Definition at line 229 of file indilogger.h.

◆ getInstance()

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 339 of file indilogger.cpp.

◆ getLogFile()

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

Definition at line 225 of file indilogger.h.

◆ initProperties()

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

Definition at line 85 of file indilogger.cpp.

◆ ISNewSwitch()

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

Definition at line 145 of file indilogger.cpp.

◆ print()

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

Definition at line 372 of file indilogger.cpp.

◆ rank()

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 348 of file indilogger.cpp.

◆ saveConfigItems()

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

Definition at line 136 of file indilogger.cpp.

◆ updateProperties()

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

Definition at line 113 of file indilogger.cpp.

Member Data Documentation

◆ ConfigurationS

ISwitch INDI::Logger::ConfigurationS
static

Definition at line 215 of file indilogger.h.

◆ ConfigurationSP

ISwitchVectorProperty INDI::Logger::ConfigurationSP
static

Definition at line 216 of file indilogger.h.

◆ customLevel

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

Definition at line 222 of file indilogger.h.

◆ DebugLevelS

ISwitch INDI::Logger::DebugLevelS
static

Definition at line 271 of file indilogger.h.

◆ DebugLevelSInit

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

Definition at line 267 of file indilogger.h.

◆ DebugLevelSP

ISwitchVectorProperty INDI::Logger::DebugLevelSP
static

Definition at line 272 of file indilogger.h.

◆ defaultlevel

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

Definition at line 210 of file indilogger.h.

◆ file_off

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

Definition at line 219 of file indilogger.h.

◆ file_on

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

Definition at line 218 of file indilogger.h.

◆ LoggingLevelS

ISwitch INDI::Logger::LoggingLevelS
static

Definition at line 213 of file indilogger.h.

◆ LoggingLevelSInit

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

Definition at line 211 of file indilogger.h.

◆ LoggingLevelSP

ISwitchVectorProperty INDI::Logger::LoggingLevelSP
static

Definition at line 214 of file indilogger.h.

◆ nDevices

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

Definition at line 223 of file indilogger.h.

◆ nlevels

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

Definition at line 211 of file indilogger.h.

◆ screen_off

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

Definition at line 221 of file indilogger.h.

◆ screen_on

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

Definition at line 220 of file indilogger.h.

◆ Tags

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 276 of file indilogger.h.


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