TwiceAsNice
2019-02-18
|
The Logger class is a simple logger to log messages to file and INDI clients. More...
#include <indilogger.h>
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 Logger & | getInstance () |
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 Logger & | getInstance () |
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 Logger * | m_ = 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::DefaultDevice * | parentDevice = nullptr |
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.
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.
typedef loggerConf_ INDI::Logger::loggerConf |
typedef loggerConf_ INDI::Logger::loggerConf |
|
private |
Type used for the configuration.
Enumerator | |
---|---|
L_nofile_ | |
L_file_ | |
L_noscreen_ | |
L_screen_ | |
L_nofile_ | |
L_file_ | |
L_noscreen_ | |
L_screen_ |
|
private |
Type used for the configuration.
Enumerator | |
---|---|
L_nofile_ | |
L_file_ | |
L_noscreen_ | |
L_screen_ | |
L_nofile_ | |
L_file_ | |
L_noscreen_ | |
L_screen_ |
|
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.
|
private |
Destructor.
It only closes the file, if open, and cleans memory.
|
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.
|
private |
Destructor.
It only closes the file, if open, and cleans memory.
Adds a new debugging level to the driver.
debugLevelName | The descriptive debug level defined to the client. e.g. Scope Status |
LoggingLevelName | the short logging level recorded in the logfile. e.g. SCOPE |
Adds a new debugging level to the driver.
debugLevelName | The descriptive debug level defined to the client. e.g. Scope Status |
LoggingLevelName | the short logging level recorded in the logfile. e.g. SCOPE |
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.
outputFile | of the file used for logging |
configuration | (i.e., log on file and on screen on or off) |
fileVerbosityLevel | threshold for file |
screenVerbosityLevel | threshold for screen |
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.
outputFile | of the file used for logging |
configuration | (i.e., log on file and on screen on or off) |
fileVerbosityLevel | threshold for file |
screenVerbosityLevel | threshold for screen |
|
inlinestatic |
|
inlinestatic |
|
static |
Method to get a reference to the object (i.e., Singleton) It is a static method.
|
static |
Method to get a reference to the object (i.e., Singleton) It is a static method.
|
inlinestatic |
|
inlinestatic |
|
static |
|
static |
|
static |
|
static |
|
inlinestaticprivate |
Method to lock in case of multithreading.
|
inlinestaticprivate |
Method to lock in case of multithreading.
void INDI::Logger::print | ( | const char * | devicename, |
const unsigned int | verbosityLevel, | ||
const std::string & | sourceFile, | ||
const int | codeLine, | ||
const char * | message, | ||
... | |||
) |
void INDI::Logger::print | ( | const char * | devicename, |
const unsigned int | verbosityLevel, | ||
const std::string & | sourceFile, | ||
const int | codeLine, | ||
const char * | message, | ||
... | |||
) |
|
static |
Method used to print message called by the DEBUG() macro.
i | which debugging to query its rank. The lower the rank, the more priority it is. |
|
static |
Method used to print message called by the DEBUG() macro.
i | which debugging to query its rank. The lower the rank, the more priority it is. |
|
static |
|
static |
|
inlinestaticprivate |
Method to unlock in case of multithreading.
|
inlinestaticprivate |
Method to unlock in case of multithreading.
|
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.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
staticprivate |
Verbosity threshold for files.
|
private |
Initial time (used to print relative times)
|
staticprivate |
Directory where log file is stored.
it is created under ~/.indi/logs/[DATE]/[DRIVER_EXEC]
|
staticprivate |
Initial part of the name of the file used for Logging.
Date and time are automatically appended.
|
static |
|
static |
|
static |
|
staticprivate |
Pointer to the unique Logger (i.e., Singleton)
|
static |
|
static |
|
private |
Stream used when logging on a file.
|
staticprivate |
|
staticprivate |
|
static |
|
static |
|
staticprivate |
Verbosity threshold for screen.
|
static |