The application can have several log levels depending on the severity/importance. The following log levels have been inspired by log4j . The following log levels are supported (in increasing order of priority):
The Application using liblogger can decide the logs above a certain level it wants to appear. For example, if a source file contains all the above logs and the desired log level is set as Warn, then only logs with equal / higher priority than Warn (i.e the Warn, Error, Fatal) logs will appear, all the below logs will be made null statements during compilation phase without any runtime overhead. The log level can be set
- Trace (LOG_LEVEL_TRACE) - Messages with fine details.
- Debug (LOG_LEVEL_DEBUG) - Debug messages.
- Info (LOG_LEVEL_INFO) - Some informational messages
- Warn (LOG_LEVEL_WARN) - Warnings
- Error (LOG_LEVEL_ERROR) - Errors during execution of a program, but the application can still continue to run.
- Fatal (LOG_LEVEL_FATAL) - Critical Errors which can lead the application to stop executing.
The following are the initalization functions:
Logging functions ( usage is similar to printf() ) :
Log entry / exit from function (same priority as of Trace level log):
- on per-source file basis, for example in a project with several src files, one file can have max log level of Info and another file can have max log level as Fatal.
- A group of files can share the same log settings.
The above functions are thread safe (unless thread safety is disabled during build).
The output of the the log depends on the variadic macro support of the compiler. To include the module name, the filename, the function name and the line number in the generated log the compiler must support variadic macros. The following compilers have this feature:
- LogFuncEntry() : Logs the entry to a function, add it at the begining of a function.
- LogFuncExit() : Logs return from a function, the best place to use it is before a
return from a function.
- The function entry and function exit logs have the same priority of log level Trace.
- A sample function entry log will look like this:
NOTE: An open braces is inserted by the function log entry and a closing braces is added by function exit log, this is to facilitate isolation of logs that appear between function calls and to identify nested function calls. Also this is very helpful when the log is being veiwed in editors (like vim) which support braces matching.
- A function exit log will look like this:
FunctionName : <line-number> }
Example (compiler with variadic macro support):
- The output of other log functions (LogDebug(), LogInfo(), ..... ) depend on the variadic macro support of the compiler. If the variadic macro support is available, then a sample log will look like:
If the variadic macro support is not available, the log will look like: