https://github.com/sh7ven/clog
A header-only, simple and thread-safe logging library written in C.
https://github.com/sh7ven/clog
c lightweight logging simple thread-safe
Last synced: about 1 year ago
JSON representation
A header-only, simple and thread-safe logging library written in C.
- Host: GitHub
- URL: https://github.com/sh7ven/clog
- Owner: sh7ven
- License: mit
- Created: 2024-08-12T18:43:56.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-10T08:12:05.000Z (over 1 year ago)
- Last Synced: 2025-05-05T18:35:47.213Z (about 1 year ago)
- Topics: c, lightweight, logging, simple, thread-safe
- Language: C
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Clog
A header-only, simple and thread-safe logging library written in C.
# Installation
Clone the repository and place the source files inside your project.
```
$ git clone https://github.com/sh7ven/Clog/
```
Add `clog.h` to an include directory, and add it to a build script as well.
For instance:
```make
# File names alongside are Project's dependencies.
Project: include/file1.h src/file1.c ... include/clog.h
@gcc $(SOME_FLAGS) -I./include/ src/*
```
See [GNU Make](https://www.gnu.org/software/make/).
# Usage
The function definition for logging is:
```c
void clog_log(clog_priority priority, FILE* stream, const char* fmt, ...)
```
For instance
```c
clog_log( CLOG_WARN, stdout, "This is some warning where an invalid access was made to the address %p", 0x0f0f );
```

You can also use some macros to quickly pipe output, instead of specifying a priority level everytime:
```
clog_info(...)
clog_debug(...)
clog_warn(...)
clog_err(...)
```
# Save logs to file
You can instruct Clog to save logs to a backup file as well.
```c
// Call this before logging any output.
clog_backup_logs(true);
```
This file is platform specific and is opened as soon you include `clog.h`.
On Linux distributions, it is `$XDG_CONFIG_HOME/clogfile` or `$HOME/.config/clogfile`.
On Windows, it is `..\AppData\clogfile`.
# TODOs
- Better cross platform support for Windows and Mac.
- Better thread safety.
- Pure private functions (hard) to prevent unnecessary problems.
# License
[MIT](https://opensource.org/license/MIT)