Simple C logger that prints ASCII color-coded messages to the terminal and can optionally mirror them to a log file.
The entire public interface lives in logger.h; compile logger.c once and link it with the rest of your program.
| Capability | Details |
|---|---|
| Severity levels | INFO, WARN, ERROR, FATAL |
| ANSI colours | Each level maps to an ANSI escape sequence for easy scanning of console output |
| Optional file log | Call logger_init() with write_to_file = 1 to also append/write to log.txt |
# Clone and build demo
git clone https://github.com/jacobismael/clogger.git
cd clogger
gcc main.c logger.c -o demo # produces ./demo
./demo # run it#include "logger.h"
int main()
{
logger_init(1, APPEND); // also write to log.txt
log_msg(INFO, "System up");
log_msg(WARN, "Battery low");
log_msg(ERROR, "Sensor failure");
log_msg(FATAL, "Emergency stop");
logger_shutdown();
return 0;
}- Thread-safety for multi-core applications
- Time-stamps on each log line
- Customizable log file name and location
- Compile-time color-disable switch for non-ANSI terminals