https://github.com/prashantrahul141/nhlog
An extremely simple logging library for C/C++ with colors.
https://github.com/prashantrahul141/nhlog
c cpp logging
Last synced: about 1 month ago
JSON representation
An extremely simple logging library for C/C++ with colors.
- Host: GitHub
- URL: https://github.com/prashantrahul141/nhlog
- Owner: prashantrahul141
- License: unlicense
- Created: 2024-08-19T22:24:04.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-11T12:38:54.000Z (over 1 year ago)
- Last Synced: 2025-02-11T13:41:02.189Z (over 1 year ago)
- Topics: c, cpp, logging
- Language: C
- Homepage:
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nhlog
An extremely simple logging library for C/C++ with colors.

# Installation
Just include the two files `nhlog.h` and `nhlog.c` with your project files and make sure to compile and link them with your project and it just works.
# Usage
```c
/* all logging can be disabled completely at compile time by defining NHLOG_DISABLE, see nhlog.h */
// #define NHLOG_DISABLE
#include "nhlog.h"
int main() {
/* Zero initialisation needed */
TRACE("least important messages");
DEBUG("debug messages");
INFO("general info message");
WARN("warnings");
ERROR("errors");
FATAL("unrecoverable crashes");
/* Logging level can be changed at runtime using: */
nhlog_set_level(NHLOG_INFO);
TRACE("this will be NOT be logged");
WARN("however this will be logged");
/* All logging can be disabled by setting log level to NHLOG_OFF */
nhlog_set_level(NHLOG_OFF);
TRACE("this will be NOT be logged");
nhlog_set_level(NHLOG_TRACE);
/* you can log to any stream by passing it to nhlog_set_outstream */
FILE *fd = fopen("logs.txt", "w");
nhlog_set_outstream(fd);
/* you may also want to disable color output for files*/
nhlog_set_output_colors(false);
TRACE("these messages will now be logged to the file.");
DEBUG("debug message");
fclose(fd);
/* setting to null defaults to stderr */
nhlog_set_output_colors(true);
nhlog_set_outstream(NULL);
/* by default output stream if flushed after every log event, but it can be
* disabled */
nhlog_set_immediate(false);
TRACE("These messages will be now buffered by the c runtime");
return 0;
}
```
# Why?
Because every other C/C++ logging library is either
- overly complicated for small projects
- doesn't support both c and c++
- doesn't have colors
- doesn't have simple api