TwiceAsNice  2019-02-18
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
INDI::Logger Class Reference

The Logger class is a simple logger to log messages to file and INDI clients. More...

#include <indilogger.h>

Inheritance diagram for INDI::Logger:
Inheritance graph
Collaboration diagram for INDI::Logger:
Collaboration graph

Classes

struct  switchinit
 

Public Types

enum  VerbosityLevel {
  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,
  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
}
 
enum  VerbosityLevel {
  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,
  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
 
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. More...
 
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. 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 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]
 

Private Types

enum  loggerConf_ {
  L_nofile_ = 1 << 0, L_file_ = 1 << 1, L_noscreen_ = 1 << 2, L_screen_ = 1 << 3,
  L_nofile_ = 1 << 0, L_file_ = 1 << 1, L_noscreen_ = 1 << 2, L_screen_ = 1 << 3
}
 Type used for the configuration. More...
 
enum  loggerConf_ {
  L_nofile_ = 1 << 0, L_file_ = 1 << 1, L_noscreen_ = 1 << 2, L_screen_ = 1 << 3,
  L_nofile_ = 1 << 0, L_file_ = 1 << 1, L_noscreen_ = 1 << 2, L_screen_ = 1 << 3
}
 Type used for the configuration. More...
 

Private Member Functions

 Logger ()
 Constructor. More...
 
 ~Logger ()
 Destructor. More...
 
 Logger ()
 Constructor. More...
 
 ~Logger ()
 Destructor. More...
 

Static Private Member Functions

static void lock ()
 Method to lock in case of multithreading. More...
 
static void unlock ()
 Method to unlock in case of multithreading. More...
 
static void lock ()
 Method to lock in case of multithreading. More...
 
static void unlock ()
 Method to unlock in case of multithreading. More...
 

Private Attributes

bool configured_ { false }
 
std::ofstream out_
 Stream used when logging on a file. More...
 
struct timeval initialTime_
 Initial time (used to print relative times) More...
 

Static Private Attributes

static Loggerm_ = nullptr
 Pointer to the unique Logger (i.e., Singleton) More...
 
static std::string logFile_
 Initial part of the name of the file used for Logging. More...
 
static std::string logDir_
 Directory where log file is stored. More...
 
static loggerConf_ configuration_ = Logger::screen_on | Logger::file_off
 Current configuration of the logger. More...
 
static unsigned int fileVerbosityLevel_ = Logger::defaultlevel
 Verbosity threshold for files. More...
 
static unsigned int screenVerbosityLevel_ = Logger::defaultlevel
 Verbosity threshold for screen. More...
 
static unsigned int rememberscreenlevel_ = Logger::defaultlevel
 
static INDI::DefaultDeviceparentDevice = nullptr
 

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.

Member Typedef Documentation

◆ loggerConf [1/2]

◆ loggerConf [2/2]

Member Enumeration Documentation

◆ loggerConf_ [1/2]

Type used for the configuration.

Enumerator
L_nofile_ 
L_file_ 
L_noscreen_ 
L_screen_ 
L_nofile_ 
L_file_ 
L_noscreen_ 
L_screen_ 

◆ loggerConf_ [2/2]

Type used for the configuration.

Enumerator
L_nofile_ 
L_file_ 
L_noscreen_ 
L_screen_ 
L_nofile_ 
L_file_ 
L_noscreen_ 
L_screen_ 

◆ VerbosityLevel [1/2]

Enumerator
DBG_ERROR 
DBG_WARNING 
DBG_SESSION 
DBG_DEBUG 
DBG_EXTRA_1 
DBG_EXTRA_2 
DBG_EXTRA_3 
DBG_EXTRA_4 
DBG_ERROR 
DBG_WARNING 
DBG_SESSION 
DBG_DEBUG 
DBG_EXTRA_1 
DBG_EXTRA_2 
DBG_EXTRA_3 
DBG_EXTRA_4 

◆ VerbosityLevel [2/2]

Enumerator
DBG_ERROR 
DBG_WARNING 
DBG_SESSION 
DBG_DEBUG 
DBG_EXTRA_1 
DBG_EXTRA_2 
DBG_EXTRA_3 
DBG_EXTRA_4 
DBG_ERROR 
DBG_WARNING 
DBG_SESSION 
DBG_DEBUG 
DBG_EXTRA_1 
DBG_EXTRA_2 
DBG_EXTRA_3 
DBG_EXTRA_4 

Constructor & Destructor Documentation

◆ Logger() [1/2]

INDI::Logger::Logger ( )
private

Constructor.

It is a private constructor, called only by getInstance() and only the first time. It is called inside a lock, so lock inside this method is not required. It only initializes the initial time. All configuration is done inside the configure() method.

◆ ~Logger() [1/2]

INDI::Logger::~Logger ( )
private

Destructor.

It only closes the file, if open, and cleans memory.

◆ Logger() [2/2]

INDI::Logger::Logger ( )
private

Constructor.

It is a private constructor, called only by getInstance() and only the first time. It is called inside a lock, so lock inside this method is not required. It only initializes the initial time. All configuration is done inside the configure() method.

◆ ~Logger() [2/2]

INDI::Logger::~Logger ( )
private

Destructor.

It only closes the file, if open, and cleans memory.

Member Function Documentation

◆ addDebugLevel() [1/2]

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.

◆ addDebugLevel() [2/2]

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.

◆ configure() [1/2]

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

◆ configure() [2/2]

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

◆ getConfiguration() [1/2]

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

◆ getConfiguration() [2/2]

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

◆ getInstance() [1/2]

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.

◆ getInstance() [2/2]

static 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.

◆ getLogFile() [1/2]

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

◆ getLogFile() [2/2]

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

◆ initProperties() [1/2]

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

◆ initProperties() [2/2]

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

◆ ISNewSwitch() [1/2]

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

◆ ISNewSwitch() [2/2]

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

◆ lock() [1/2]

void INDI::Logger::lock ( )
inlinestaticprivate

Method to lock in case of multithreading.

◆ lock() [2/2]

static void INDI::Logger::lock ( )
inlinestaticprivate

Method to lock in case of multithreading.

◆ print() [1/2]

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

◆ print() [2/2]

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

◆ rank() [1/2]

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.

◆ rank() [2/2]

static 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.

◆ saveConfigItems() [1/2]

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

◆ saveConfigItems() [2/2]

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

◆ unlock() [1/2]

static void INDI::Logger::unlock ( )
inlinestaticprivate

Method to unlock in case of multithreading.

◆ unlock() [2/2]

void INDI::Logger::unlock ( )
inlinestaticprivate

Method to unlock in case of multithreading.

◆ updateProperties() [1/2]

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

◆ updateProperties() [2/2]

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

Member Data Documentation

◆ configuration_

static loggerConf_ INDI::Logger::configuration_ = Logger::screen_on | Logger::file_off
staticprivate

Current configuration of the logger.

Variable to know if logging on file and on screen are enabled. Note that if the log on file is enabled, it means that the logger has been already configured, therefore the stream is already open.

◆ ConfigurationS

static ISwitch INDI::Logger::ConfigurationS
static

◆ ConfigurationSP

static ISwitchVectorProperty INDI::Logger::ConfigurationSP
static

◆ configured_

bool INDI::Logger::configured_ { false }
private

◆ customLevel

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

◆ DebugLevelS

static ISwitch INDI::Logger::DebugLevelS
static

◆ DebugLevelSInit

static struct switchinit INDI::Logger::DebugLevelSInit
static

◆ DebugLevelSP

static ISwitchVectorProperty INDI::Logger::DebugLevelSP
static

◆ defaultlevel

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

◆ file_off

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

◆ file_on

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

◆ fileVerbosityLevel_

static unsigned int INDI::Logger::fileVerbosityLevel_ = Logger::defaultlevel
staticprivate

Verbosity threshold for files.

◆ initialTime_

struct timeval INDI::Logger::initialTime_
private

Initial time (used to print relative times)

◆ logDir_

static std::string INDI::Logger::logDir_
staticprivate

Directory where log file is stored.

it is created under ~/.indi/logs/[DATE]/[DRIVER_EXEC]

◆ logFile_

static std::string INDI::Logger::logFile_
staticprivate

Initial part of the name of the file used for Logging.

Date and time are automatically appended.

◆ LoggingLevelS

static ISwitch INDI::Logger::LoggingLevelS
static

◆ LoggingLevelSInit

static struct switchinit INDI::Logger::LoggingLevelSInit
static

◆ LoggingLevelSP

static ISwitchVectorProperty INDI::Logger::LoggingLevelSP
static

◆ m_

static Logger * INDI::Logger::m_ = nullptr
staticprivate

Pointer to the unique Logger (i.e., Singleton)

◆ nDevices

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

◆ nlevels

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

◆ out_

std::ofstream INDI::Logger::out_
private

Stream used when logging on a file.

◆ parentDevice

static INDI::DefaultDevice * INDI::Logger::parentDevice = nullptr
staticprivate

◆ rememberscreenlevel_

static unsigned int INDI::Logger::rememberscreenlevel_ = Logger::defaultlevel
staticprivate

◆ screen_off

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

◆ screen_on

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

◆ screenVerbosityLevel_

static unsigned int INDI::Logger::screenVerbosityLevel_ = Logger::defaultlevel
staticprivate

Verbosity threshold for screen.

◆ Tags

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

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