A simple, lightweight logging library for C projects.
Make sure you have the standard build tools installed:
sudo apt install build-essentialYou can build either a static or a shared (dynamic) library depending on your needs.
To build a static library:
make releaseOutput: bin/qlog.a
To build a shared (dynamic) library:
make release_sharedOutput: bin/qlog.so
- Build the library using the instructions above.
- Add the include directory to your compiler flags (e.g.,
-IIncludes/). - Link the compiled library (
bin/qlog.aorbin/qlog.so) to your project.
To enable logging, define the LOG_ON macro before including the header file.
#define LOG_ON
#include "log.h"
int main() {
LOGI("HELLO LOGS");
return 0;
}You can configure the logger by creating a qlog.config file in your working directory.
Here is an example configuration:
FMT="_%l_ [%f] %p:%n\n\t"
DATE_FMT="[%H:%M:%S]"
LEVEL="DEBUG"
WR_STDERR=1
WR_FILE=0
LOG_ON=1
FILEPATH="test.log"FMT— The log output format. Available format specifiers:%l— Log level (e.g., DEBUG, INFO)%f— Function name%p— File path%n— Line number
DATE_FMT— The date and time format.LEVEL— Minimum log level to record (e.g.,DEBUG).WR_STDERR— Write logs tostderr(1to enable,0to disable).WR_FILE— Write logs to a file (1to enable,0to disable).LOG_ON— Global switch to enable (1) or disable (0) logging entirely.FILEPATH— Path to the log file (used ifWR_FILE=1).