https://github.com/karnkaul/dlog
Dumb logger library
https://github.com/karnkaul/dlog
cpp cpp17 cpp17-library logging
Last synced: 11 months ago
JSON representation
Dumb logger library
- Host: GitHub
- URL: https://github.com/karnkaul/dlog
- Owner: karnkaul
- License: gpl-3.0
- Created: 2020-10-25T21:44:41.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-02-07T12:45:04.000Z (almost 4 years ago)
- Last Synced: 2025-01-25T06:11:21.117Z (about 1 year ago)
- Topics: cpp, cpp17, cpp17-library, logging
- Language: C++
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dumb Log
[](https://github.com/karnkaul/dlog/actions/workflows/ci.yml)
This is a "dumb simple" logging library that uses [fmt](https://github.com/fmtlib/fmt).
## Features
- Publicly integrated `fmt`
- Reentrant and thread-safe functions
- MSVC Output Window (`OutputDebugStringA`)
- Separate `format()` function
- Log levels: `error`, `warn`, `info`, `debug`
- Meta-format: add `level`, `thread`, and `timestamp` text around message
- Async file logging (optional)
- Attach custom output `pipe`s
- Customizable output channels (`unsigned char` bit flags)
## Limitations
- `char` and `std::string` support only (no wide strings)
- No support for domain based logging / filtering
## Usage
### Requirements
- CMake 3.14+
- C++17 compiler (and stdlib)
### Steps
1. Clone repo to appropriate subdirectory, say `dumb_log`
1. Add library to project via: `add_subdirectory(dumb_log)` and `target_link_libraries(foo dlog::dlog)`
1. Use via: `#include `
1. Use only fmt via: `#include `
### Examples
#### Simple
```cpp
dumb_log::set_log_format("[{level}] [T{thread}] {message} [{timestamp}]");
dumb_log::info("{} and {} successfully initialised", "Instance", "Device");
/* output:
[I] [T0] Instance and Device successfully initialised [21:23:18]
*/
```
#### File Logging
```cpp
{
// start thread capturing logs asynchronously into passed file path
// backs up existing file if any (suffix can be customized)
// obtain RAII handle
auto handle = dumb_log::file_logger::attach("log.txt");
// ...
} // thread joined
```
#### Custom Pipes
```cpp
struct my_pipe : dumb_log::pipe {
dumb_log::level min_level;
my_pipe(dumb_log::level min_level) noexcept : min_level(min_level) {}
void operator()(dumb_log::level l, std::string_view line) const override {
if (l >= min_level) {
/* custom logic */
}
}
};
{
auto handle = dumb_log::pipe::attach(dumb_log::level::info);
// ...
}
```
### Contributing
Pull/merge requests are welcome.