A simple logging library implemented in C99
log.c and log.h should be dropped into an existing project and compiled along with it. The library provides 6 function-like macros for logging:
log_trace(const char *fmt, ...);
log_debug(const char *fmt, ...);
log_info(const char *fmt, ...);
log_warn(const char *fmt, ...);
log_error(const char *fmt, ...);
log_fatal(const char *fmt, ...);
Each function takes a printf format string followed by additional arguments:
log_trace("Hello %s", "world")
Resulting in a line with the given format printed to standard output:
20:18:26 TRACE src/main.c:11: Hello world
And to the output files:
2047-03-11 20:18:26 TRACE src/main.c:11: Hello world
Detailed documentation is provided in the 'log.h' file
To alter the default settings, the library has to be compiled with the 'LOGC__USER_SETTINGS' flag. This way, a 'log_conf.h' file can be specified to alter the default settings.
Differences with the original project from rxi
The most interesting pull-requests (to me at least) have been integrated. Thanks to the following for their indirect contribution:
- flemingoo, Log levels re-ordering
- dianjixz, C++ support
- chiefnoah, Log levels renaming to avoid conflicts with Syslog
- Allenhe123, Example with threads
My changes:
- Code indentation changed to 4 spaces
- Added doxygen-style documentation for all functions and structures
- Log levels enum converted to a typedef
- Ability to configure library with the 'log_conf.h' file
- Renamed 'udata' variables in code to more meaningful
- Added sample source files
- basic Is a basic example, to log to stdout and to a file
- callbacks Is a minimal example using callbacks with different log levels
- threading Shows a threading example
This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.