A simple and small plug in and play logging library in C. Modified version of rxi/log.c
Copy log.h into your project and choose exactly 1 source file, in which LOGC_SOURCE should be defined before including log.h (see the example below).
Copy log.h and log.c into your project and add log.c to your source files.
The following example shows how to use log.h:
#define LOGC_LEADING_TEXT "[CustomTextInThisFile] "
#define LOGC_SOURCE // only 1 source file should set this! (or add log.c to your source files)
#include "log.h"
int main() {
// log modes:
log_trace("trace msg");
log_debug("debug msg");
log_info("info msg");
log_warn("warn msg");
log_error("error msg");
log_wtf("wtf msg");
// if the macro LOGC_LEADING_TEXT is set, a custom string is placed before each log
// see above
// or the comment in CMakeLists.txt: add_definitions(-DLOGC_LEADING_TEXT="[CustomText] ")
// all log macros are in printf style:
log_debug("value: %d", 34);
// also print fo file:
FILE *logfile = fopen("log.txt", "a");
logc_set_log_file(logfile);
log_info("also in file");
logc_set_quiet(true);
log_info("only in file");
logc_set_min_level(LOG_WARN);
log_info("this log will be discarded");
fclose(logfile);
}
Its also possible to change the namespace logc_ with LOGC_NAMESPACE
If you use Logc in a C Library, that will be exposed to python, a binding to logc is in log.py. Just change some lines at the top and have fun.
- René Horstmann
- rxi
This project is licensed under the MIT License - see the LICENSE file for details