KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
log.h File Reference

Implements a generic logger facility. More...

#include <stdbool.h>
#include <stdint.h>
#include "util/macro.h"

Go to the source code of this file.

Data Structures

struct  LogModInfo
 Module info structure. More...
 

Macros

#define LOG_MODE   LOG_MODE_INFO
 Set the compile time supported log modes. More...
 
#define LOG_NO_NONE   0x0
 
#define LOG_LEVEL_DEFAULT   logLevelInfo
 The default logging level.
 
#define LOG_DEF_LVL(NAME, LEVEL)   static LogModInfo _logModInfo = { .name = STR(NAME), .level = LEVEL };
 Define a logger for a module. More...
 
#define LOG_DEF(NAME,...)   LOG_DEF_LVL(NAME, LOG_LEVEL_DEFAULT)
 Define a logger for a module. More...
 
#define logTrace(MSG,...)
 
#define logDebug(MSG,...)
 
#define logInfo(MSG,...)   _logWrite(&_logModInfo, logLevelInfo, MSG, ## __VA_ARGS__)
 Write a log message with formatting on info level. More...
 
#define logWarn(MSG,...)   _logWrite(&_logModInfo, logLevelWarn, MSG, ## __VA_ARGS__)
 Format a log message with warning level. More...
 
#define logError(MSG,...)   _logWrite(&_logModInfo, logLevelError, MSG, ## __VA_ARGS__)
 Format a log message with fatal level. More...
 
Logging Options
See Also
LOG_MODE
#define LOG_MODE_TRACE   1
 Log everything, including TRACING.
 
#define LOG_MODE_DEBUG   2
 Log DEBUG and up. More...
 
#define LOG_MODE_INFO   3
 Log INFO and up.
 
#define LOG_MODE_EXCEPT   4
 Log WARN, ERROR AND FATAL.
 
#define LOG_MODE_NOTHING   5
 Log nothing.
 

Enumerations

enum  LogLevel {
  logLevelTrace, logLevelDebug, logLevelInfo, logLevelWarn,
  logLevelError, logLevelFatal, logLevelDisabled
}
 Logging levels. More...
 

Functions

void _logWrite (LogModInfo *mod, LogLevel level, const char *msg,...)
 Write a logging statement. More...
 
void _logOut (LogLevel level, char *logLine)
 External dependency function. More...
 
void logEnable (bool enable)
 Enable logging. More...
 
void logSetGlobalLevel (LogLevel level)
 Set the global log level. More...
 
uint32_t _logTime ()
 Stub function, which should return the current time in seconds, since whatever. More...
 

Detailed Description

Implements a generic logger facility.

The logger can define a lowest logging level during compile time. All logging statements lower than this level will be removed from the compile, thus saving space.

Definition in file log.h.

Macro Definition Documentation

#define LOG_DEF (   NAME,
  ... 
)    LOG_DEF_LVL(NAME, LOG_LEVEL_DEFAULT)

Define a logger for a module.

Must be done INSIDE the C file, not in an header, since a variable named '_logModInfo' will be defined. Putting it in a header will cause name collisions.

The level will be set to default. If you wish to specify a level use LOG_DEF_LVL().

Parameters
NAMEthe name, without quotes.

Definition at line 129 of file log.h.

#define LOG_DEF_LVL (   NAME,
  LEVEL 
)    static LogModInfo _logModInfo = { .name = STR(NAME), .level = LEVEL };

Define a logger for a module.

Must be done INSIDE the C file, not in an header, since a variable named '_logModInfo' will be defined. Putting it in a header will cause name collisions.

Parameters
NAMEthe name, without quotes.
LEVELthe level of the logger.

Definition at line 114 of file log.h.

#define LOG_MODE   LOG_MODE_INFO

Set the compile time supported log modes.

Anything below this will be compiled away IF log<Level>() macro's are used.

Definition at line 60 of file log.h.

#define LOG_MODE_DEBUG   2

Log DEBUG and up.

Definition at line 43 of file log.h.

#define logError (   MSG,
  ... 
)    _logWrite(&_logModInfo, logLevelError, MSG, ## __VA_ARGS__)

Format a log message with fatal level.

Attention
{ Assumes the usage of LOG_DEF() or LOG_DEF_LVL(). }
Parameters
MSGThe formatting string.
...Parameters

Definition at line 232 of file log.h.

#define logInfo (   MSG,
  ... 
)    _logWrite(&_logModInfo, logLevelInfo, MSG, ## __VA_ARGS__)

Write a log message with formatting on info level.

Using this function allows the compiler to remove the call completely if the compile time level is higher than LOG_MODE_INFO.

Attention
Assumes the usage of LOG_DEF() or LOG_DEF_LVL().
Parameters
MSGThe message.

Definition at line 202 of file log.h.

#define logWarn (   MSG,
  ... 
)    _logWrite(&_logModInfo, logLevelWarn, MSG, ## __VA_ARGS__)

Format a log message with warning level.

Attention
{ Assumes the usage of LOG_DEF() or LOG_DEF_LVL(). }
Parameters
MSGThe formatting string.
...Parameters

Definition at line 219 of file log.h.

Enumeration Type Documentation

enum LogLevel

Logging levels.

Enumerator
logLevelTrace 

Trace, show detailed runtime information.

logLevelDebug 

Debug, shows information only interesting during debugging.

logLevelInfo 

Info, general information.

logLevelWarn 

System warning, system can continue.

logLevelError 

Error, system will continue, but may malfunction.

logLevelFatal 

Fatal, system can not continue and will reboot.

logLevelDisabled 

Disabled, not really a level, but used to disable logging.

Definition at line 68 of file log.h.

Function Documentation

void _logOut ( LogLevel  level,
char *  logLine 
)

External dependency function.

Function should output or store the given log line.

Parameters
levelLog level
logLineThe logline to log.

Output to Log

Definition at line 353 of file sys.c.

uint32_t _logTime ( )

Stub function, which should return the current time in seconds, since whatever.

Returns
A uint32_t with the current time in seconds.

Definition at line 201 of file sys.c.

void _logWrite ( LogModInfo mod,
LogLevel  level,
const char *  msg,
  ... 
)

Write a logging statement.

Normally internally used

Parameters
modPointer to the source module that generated the message.
levelThe log level of the message.
msgThe actual message
...The parameters to be formatted into the mssage

Definition at line 66 of file log.c.

void logEnable ( bool  enable)

Enable logging.

Parameters
enableSet to true to enable logging, false to supress everything.

Definition at line 79 of file log.c.

void logSetGlobalLevel ( LogLevel  level)

Set the global log level.

No matter what the log level is of the various modules, no messages will be displayed below this level.

Parameters
levelThe minum level to show.

Definition at line 85 of file log.c.