https://github.com/slayers-git/slog
Fast and customizable logging library for C/C++
https://github.com/slayers-git/slog
c89 customizable library logging
Last synced: 7 months ago
JSON representation
Fast and customizable logging library for C/C++
- Host: GitHub
- URL: https://github.com/slayers-git/slog
- Owner: slayers-git
- License: lgpl-2.1
- Created: 2021-07-14T15:11:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-25T13:26:03.000Z (over 3 years ago)
- Last Synced: 2025-03-29T14:25:06.749Z (11 months ago)
- Topics: c89, customizable, library, logging
- Language: C
- Homepage:
- Size: 55.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slog
slog is a fast and customizable logging library written in C89.
## Features
- Custom formats for the output
- Optionally colored output
- Certain log levels can be suppressed
## Example
```c
#include
int main (void) {
slog_stream *logger = slog_create ("mylog.txt", slog_flags_none);
if (!logger)
return -1;
if (slog_format (logger, "[%l] %d/%M/%Y: %L") != 0) {
return -2;
}
slog_message (logger, "My message");
const char *message = "message";
slog_printf (logger, slog_loglevel_message, "My formatted %s", message);
slog_colorized (logger, 1);
slog_error (logger, "This message now will be red (if the OS supports it)");
slog_debug (logger, "You won't see this message unless...");
slog_suppress (logger, SLOG_SUPPRESS_NOTHING);
slog_debug (logger, "Now this message is visible!");
slog_close (logger);
return 0;
}
```
More informative examples can be found in `test/` directory.
## Format
You can use the following symbols to describe your log format:
- %c - standart time representation (see: acstime ())
- %h - hours (12h)
- %H - hours (24h)
- %m - minutes
- %s - seconds
- %d - days
- %M - months
- %y - years [2 digit]
- %Y - years [4 digit]
- %l - log level
- %L - message
- %p - seconds since the start of the program
- %P - seconds since 01/01/1970
## Building
To build and install slog library on a \*nix system, in your shell type:
```bash
mkdir build && cd build\
cmake ../ && make && sudo make install
```
You can also compile the contents of the `test/` directory by appending `-DSLOG_EXAMPLES=1` to the `cmake` command.