Skip to content

Commit f966985

Browse files
committed
Initial public release: async structured logger, docs, tests, CI, all meta files
0 parents  commit f966985

25 files changed

+26296
-0
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Install build tools
15+
run: sudo apt-get update && sudo apt-get install -y g++ make
16+
- name: Build and run tests
17+
run: |
18+
g++ -std=c++17 -pthread -Iinclude tests/async_flush.cpp -o async_flush
19+
./async_flush
20+
g++ -std=c++17 -pthread -Iinclude tests/file_sink.cpp -o file_sink
21+
./file_sink
22+
g++ -std=c++17 -pthread -Iinclude tests/sync_mode.cpp -o sync_mode
23+
./sync_mode
24+
g++ -std=c++17 -pthread -Iinclude tests/basic.cpp -o basic
25+
./basic

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.DS_Store
2+
*.o
3+
*.obj
4+
*.exe
5+
*.out
6+
*.bin
7+
*.a
8+
*.so
9+
*.dll
10+
*.log
11+
*.db
12+
*.suo
13+
*.user
14+
*.userosscache
15+
*.sln.docstates
16+
*.swp
17+
*.dSYM/
18+
*.vcxproj*
19+
*.sln
20+
*.cproj
21+
build/
22+
CMakeFiles/
23+
cmake-build*/
24+
*.orig
25+
*.core
26+
*.tmp
27+
*.test
28+
*.t
29+
.turd*
30+
__pycache__/
31+
.env

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# cLog Changelog
2+
3+
## [v0.1.0] - 2026-02-10
4+
### Added
5+
- First public release: async by default, robust background log draining, JSON output.
6+
- File/console sink, chainable API for log creation.
7+
- Test suite for async flush, sync mode, file sink, and crash-avoidance.
8+
- Modern, minimal, single-header main implementation.
9+
10+
### Fixed
11+
- Thread shutdown is lossless—background logging thread fully drains before logger destruction.
12+
13+
---
14+
All changes will be documented in this file.

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Contributing to cLog
2+
3+
Thank you for your interest in contributing!
4+
5+
## How to Contribute
6+
1. **Fork the repository** and clone it locally.
7+
2. **Create a new branch** for each feature or fix.
8+
3. **Write clear code** and **add tests** for any new behavior.
9+
4. **Run all tests** (`g++ -std=c++17 -pthread -Iinclude tests/*.cpp && ./...`) before submitting.
10+
5. **Open a pull request** (PR) with a clear, descriptive title and summary.
11+
6. **Participate in code review**—be responsive, constructive, and open!
12+
13+
## Reporting Issues
14+
- Search for existing issues first.
15+
- Open an Issue with a clear description, steps to reproduce, your platform, and expected vs. actual behavior.
16+
- Bug reports, documentation, and feature requests all welcome!
17+
18+
## Code Style
19+
- Modern C++17. Prefer clarity, consistency, and minimal macros.
20+
- Document any public APIs in comments.
21+
- Chainable builder APIs and clear naming are preferred.
22+
23+
## License
24+
By contributing you agree your work will be licensed under the MIT license.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 cLog contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# cLog – Modern C++ Logging Library
2+
3+
> **Frictionless, async-by-default, structured JSON logging for modern C++**
4+
5+
## Quickstart Example
6+
```cpp
7+
#include "logger.hpp"
8+
int main() {
9+
Logger log;
10+
log.info("system.start").kv("version", "1.0");
11+
}
12+
```
13+
**First log call launches a background worker thread for async output by default.**
14+
15+
---
16+
17+
## Features (Design Table)
18+
| Feature | Approach |
19+
|-------------------------|-----------------------------------------------------------------|
20+
| Installation | Single header, instant use, nlohmann/json is fully internal |
21+
| First Log | Async by default—first use launches worker thread, documented up front |
22+
| Sync Mode | Compile-time build flag for full sync, runtime opt-in if available |
23+
| No Macros | Never used—tooling, refactoring, and debugging always work |
24+
| Structured Logs | JSON output, no user-level JSON code |
25+
| Compile-time level | Minimal overhead when disabled; eliminates dead code |
26+
| Sinks | Console/file by default; custom/extensible sinks, not required |
27+
| Debug/Stack Context | Opt-in: header, adds stacktrace/thread/context as desired |
28+
| Thread Info | Included via debug header/opt-in only |
29+
| Config | (Future) JSON/YAML—deserializes to core logger API, never magic |
30+
| Testing/CI | GoogleTest + GitHub Actions, boring, predictable, cross-platform |
31+
| Docs/Examples | Always shows one-liner start, then advanced opt-ins |
32+
33+
---
34+
35+
## Rationale and Values
36+
- **Zero-magic API**
37+
- **No macros ever**: Easy refactoring and debugging
38+
- **Async by default, never silent**: Docs and behavior preempt confusion
39+
- **Structured JSON output only**: No user-facing JSON APIs
40+
- **Extensible, but extensions never required**
41+
42+
For more, see [docs/PHILOSOPHY.md](docs/PHILOSOPHY.md) (to be added).
43+
44+
---
45+
46+
## Async and Sync Behavior
47+
- Async (background thread and queue) is the default. First log output launches async worker.
48+
- Sync mode: Compile-time flag disables async for embedded/hard-realtime, or use `Logger log(Logger::Mode::Sync);` at runtime where threads are available.
49+
50+
---
51+
52+
## Sinks and Extensibility
53+
- Output goes to stderr (JSON per line) by default
54+
- Register file or custom sinks using `.add_sink(std::make_unique<FileSink>("file.log"));`
55+
- All extensibility is opt-in. No required advanced config.
56+
57+
---
58+
59+
## Debugging, Stack, and Thread Context
60+
- Include `logger_debug.hpp` to add `.with_stacktrace()`/`.with_context()`/`.with_threadinfo()` to entries.
61+
- Zero core overhead unless debug features are requested.
62+
63+
---
64+
65+
## FAQ
66+
- **Q: Do I ever need to touch JSON types?**
67+
> Never. JSON is entirely internal.
68+
69+
- **Q: Why async by default?**
70+
> For performance. You control opt-out via build or API.
71+
72+
---
73+
74+
## License
75+
MIT. Includes vendored [nlohmann/json](https://github.com/nlohmann/json) (MIT).

examples/hello

116 KB
Binary file not shown.

examples/hello.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "../include/logger.hpp"
2+
3+
int main() {
4+
c_log::Logger log;
5+
log.info("system.start")
6+
.kv("version", "1.0")
7+
.kv("user_count", 5);
8+
// flush current record on destruction
9+
return 0;
10+
}

examples/quickstart

478 KB
Binary file not shown.

examples/quickstart.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "../include/logger.hpp"
2+
3+
int main() {
4+
Logger log; // async by default
5+
log.info("app.start").kv("version", "0.1").send();
6+
log.error("db.fail").kv("query", "SELECT * FROM foo").kv("code", 10).send();
7+
log.set_level(Logger::Level::Warning);
8+
log.warn("low.battery").kv("percent", 15).send();
9+
}

0 commit comments

Comments
 (0)