Simple logging to a file and to console.
More...
|
typedef struct vtm_log | vtm_log |
|
|
enum | vtm_log_level {
VTM_LOG_ERROR = 0,
VTM_LOG_WARN = 1,
VTM_LOG_INFO = 2,
VTM_LOG_VERBOSE = 3,
VTM_LOG_DEBUG = 4
} |
|
#define VTM_LOG_HINT_CONSOLE 1 |
#define VTM_LOG_HINT_FILE 2 |
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
-
path | where the log file should be stored. Can be NULL if VTM_LOG_HINT_FILE is not used |
name | of the logfile without extension. Can be NULL if VTM_LOG_HINT_FILE is not used |
hints | an 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
-
VTM_API void vtm_log_set_level |
( |
vtm_log * |
log, |
|
|
enum vtm_log_level |
level |
|
) |
| |
Sets which messages should be logged.
- Parameters
-
log | the log which should be updated |
level | the 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
-
log | the log which should be updated |
lines | the 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
-
log | the log which should be used |
level | the level of the message |
msg | the 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
-
log | the log which should be used |
level | the level of the message |
fmt | the message as format string |