Macros | Typedefs | Enumerations | Functions
log.h File Reference

Simple logging to a file and to console. More...

Macros

#define VTM_LOG_HINT_CONSOLE   1
 
#define VTM_LOG_HINT_FILE   2
 

Typedefs

typedef struct vtm_log vtm_log
 

Enumerations

enum  vtm_log_level {
  VTM_LOG_ERROR = 0, VTM_LOG_WARN = 1, VTM_LOG_INFO = 2, VTM_LOG_VERBOSE = 3,
  VTM_LOG_DEBUG = 4
}
 

Functions

VTM_API vtm_log * vtm_log_open (const char *path, const char *name, int hints)
 
VTM_API void vtm_log_close (vtm_log *log)
 
VTM_API void vtm_log_set_level (vtm_log *log, enum vtm_log_level level)
 
VTM_API void vtm_log_set_max_lines (vtm_log *log, unsigned long lines)
 
VTM_API void vtm_log_write (vtm_log *log, enum vtm_log_level level, const char *msg)
 
VTM_API void vtm_log_writef (vtm_log *log, enum vtm_log_level level, const char *fmt,...)
 

Macro Definition Documentation

#define VTM_LOG_HINT_CONSOLE   1

log to stdout/stderr

#define VTM_LOG_HINT_FILE   2

log to file

Function Documentation

VTM_API vtm_log* vtm_log_open ( const char *  path,
const char *  name,
int  hints 
)

Opens a new log.

The log is internally synchronized by a mutex and can be used from multiple threads simultaneously.

Parameters
pathwhere the log file should be stored. Can be NULL if VTM_LOG_HINT_FILE is not used
nameof the logfile without extension. Can be NULL if VTM_LOG_HINT_FILE is not used
hintsan OR'ed combination of the possible hints defined above.
Returns
log handle for use in the other functions
NULL if an error occured
VTM_API void vtm_log_close ( vtm_log *  log)

Closes the log and frees all allocated resources.

Parameters
logwhich shoud be closed
VTM_API void vtm_log_set_level ( vtm_log *  log,
enum vtm_log_level  level 
)

Sets which messages should be logged.

Parameters
logthe log which should be updated
levelthe threshold up to which level messages are logged
VTM_API void vtm_log_set_max_lines ( vtm_log *  log,
unsigned long  lines 
)

Sets the maximum lines a log should write to one file.

When the maximus is reached, the current logfile is renamed and a new one is opened.

Parameters
logthe log which should be updated
linesthe new maximum
VTM_API void vtm_log_write ( vtm_log *  log,
enum vtm_log_level  level,
const char *  msg 
)

Logs a simple message.

If the log level of the log is lower than the one given, the message is ignored.

Parameters
logthe log which should be used
levelthe level of the message
msgthe message which should be logged
VTM_API void vtm_log_writef ( vtm_log *  log,
enum vtm_log_level  level,
const char *  fmt,
  ... 
)

Logs a message with a format string and varargs.

The syntax for the format string is the same as for printf().

Parameters
logthe log which should be used
levelthe level of the message
fmtthe message as format string