|
1 | 1 | # Tiny Logger |
2 | 2 |
|
3 | | -A fast, lightweight, zero-dependency logging solution for Go applications that prioritizes performance and |
4 | | -simplicity. |
5 | | -Compatible with Go version 1.18.x and above |
| 3 | +A fast, lightweight, zero-dependency logging solution for Go applications that prioritizes performance and simplicity. |
6 | 4 |
|
7 | | -## ✅ Key Features |
| 5 | +This library is extremely optimized to log loosely-typed data (interfaces), so you won't have to specify concrete types before logging. |
8 | 6 |
|
9 | | -- **Lightweight**: No external dependencies mean faster builds and smaller binaries <br> |
10 | | - The dependencies that you see in the `go.mod` file are not included in the final binary since they are only used in `_test` files. |
11 | | -- **Simplicity**: Clean API design with a minimal learning curve. You'll set it up in seconds. |
| 7 | +I know that higher raw speed can be reached using other Go logging solutions, but when I created tiny-logger, I wanted to build something as fast as possible without compromising on simplicity of use. |
| 8 | +There are many projects that can benefit from having a logging library that is compact, fast, easy to use, and simple to modify. |
| 9 | +Since the codebase is so small, it won't take long for you to understand it and modify it at will. |
| 10 | + |
| 11 | +The project is compatible with **Go version 1.18.x** and above. |
| 12 | + |
| 13 | +## Key Features |
| 14 | + |
| 15 | +- **Lightweight**: The library has no dependencies, the code you see is all that runs. |
| 16 | + NOTE: The only dependencies you'll see in the `go.mod` file are not included in the final binary since they are only used in `_test` files. |
| 17 | +- **Simplicity**: I designed the API to have a minimal learning curve. You'll set it up in seconds. |
12 | 18 | - **Performance**: The library is benchmarked to be very fast. It implements custom JSON and YAML marshaling |
13 | 19 | specifically optimized for logging |
14 | | - - Up to 1.4x faster JSON marshaling than `encoding/json` |
15 | | - - Up to 5x faster YAML marshaling than `gopkg.in/yaml.v3` |
16 | | -- **Color Support**: Built-in ANSI color support for terminal output |
17 | | -- **Thread-Safe**: Concurrent-safe logging with atomic operations |
18 | | -- **Time-Optimized**: Efficient date/time print built-int logic with minimal allocations |
19 | | -- **Reliability**: Thoroughly tested with high test coverage |
20 | | -- **Maintainability**: A small, focused codebase makes it easy to understand and modify at will |
| 20 | + - Up to 1.4x faster JSON marshaling than `encoding/json` |
| 21 | + - Up to 5x faster YAML marshaling than `gopkg.in/yaml.v3` |
| 22 | +- **Color Support**: Built-in ANSI color support for terminal output. |
| 23 | +- **Thread-Safe**: Concurrent-safe logging with atomic operations. |
| 24 | +- **Time-Optimized**: Efficient date/time formatting with minimal allocations. |
| 25 | +- **Memory-Efficient**: Heap allocations and log sizes are kept to a minimum to avoid triggering the garbage collector. |
21 | 26 |
|
22 | | -## 🎯 Use Examples |
| 27 | +## Use Examples |
23 | 28 |
|
24 | 29 | ````go |
25 | 30 | /******************** Basic Logging methods usage ********************/ |
@@ -64,44 +69,64 @@ logger.SetDateTimeFormat(shared.UnixTimestamp) |
64 | 69 | logger.Debug("This is my Debug log", "Test arg") // stdout: 1690982143.000000 This is my Debug log Test arg |
65 | 70 | ```` |
66 | 71 |
|
67 | | -## 📊 Benchmark Results |
| 72 | +## Benchmarks |
| 73 | + |
| 74 | +1. Benchmarks of the **loggers-comparison-benchmark** in [Makefile](./Makefile) |
| 75 | + |
| 76 | + **NOTE:** These benchmarks intentionally log loosely-typed data across all four compared libraries. |
| 77 | + As mentioned above, libraries like **zerolog** can achieve higher performance when logging strictly-defined data types. |
| 78 | + However, since high-speed typed logging was not the primary goal of **tiny-logger**, I wanted to evaluate how it performs against industry-standard libraries when handling arbitrary data types. |
| 79 | + |
| 80 | + |
| 81 | + - **OS:** Linux |
| 82 | + - **Arch:** AMD64 |
| 83 | + - **CPU:** 12th Gen Intel(R) Core(TM) i9-12900K |
68 | 84 |
|
69 | | -This is the result of running the `./test/benchmark_test.go` benchmark on my machine, (ns/op)times do not include the |
70 | | -terminal graphical visualization time. |
| 85 | + | Logger | Iterations | Time / Op | Bytes / Op | Allocs / Op | |
| 86 | + | :--- | :--- | :--- | :--- | :--- | |
| 87 | + | **TinyLogger** | 17,625,723 | **339.9 ns** | **88 B** | **2** | |
| 88 | + | Zerolog | 12,983,034 | 460.2 ns | 232 B | 5 | |
| 89 | + | Zap | 10,391,967 | 578.3 ns | 136 B | 2 | |
| 90 | + | Logrus | 3,607,248 | 1692 ns | 1241 B | 21 | |
71 | 91 |
|
72 | | -| Encoder | Configuration | ns/op | B/op | allocs/op | |
73 | | -|---------------------|--------------------|-------|------|-----------| |
74 | | -| **Default Encoder** | All Properties OFF | 490.3 | 80 | 1 | |
75 | | -| | All Properties ON | 511.2 | 104 | 1 | |
76 | | -| **JSON Encoder** | All Properties OFF | 513.3 | 80 | 1 | |
77 | | -| | All Properties ON | 536.5 | 104 | 1 | |
78 | | -| **YAML Encoder** | All Properties OFF | 535.3 | 80 | 1 | |
79 | | -| | All Properties ON | 557.1 | 104 | 1 | |
| 92 | + - **OS:** Darwin (macOS) |
| 93 | + - **Arch:** AMD64 |
| 94 | + - **CPU:** VirtualApple @ 2.50GHz |
80 | 95 |
|
| 96 | + | Logger | Iterations | Time / Op | Bytes / Op | Allocs / Op | |
| 97 | + | :--- | :--- | :--- | :--- | :--- | |
| 98 | + | **TinyLogger** | 6,091,185 | **972.9 ns** | **88 B** | **2** | |
| 99 | + | Zerolog | 4,922,115 | 1220 ns | 232 B | 5 | |
| 100 | + | Zap | 3,938,301 | 1517 ns | 136 B | 2 | |
| 101 | + | Logrus | 1,814,809 | 3291 ns | 1241 B | 21 | |
81 | 102 |
|
82 | | -## 🤝 Contributing |
| 103 | +2. Benchmarks of the **encoders-benchmark** command contained in the [Makefile](./Makefile) |
83 | 104 |
|
84 | | -Contributions are welcome, Here's how you can help: |
| 105 | + - **OS:** Linux |
| 106 | + - **Arch:** AMD64 |
| 107 | + - **CPU:** 12th Gen Intel(R) Core(TM) i9-12900K |
85 | 108 |
|
86 | | -1. Fork the repository |
87 | | -2. Clone your fork: |
88 | | -3. Create a new branch: |
| 109 | + | Logger | Iterations | Time / Op | Bytes / Op | Allocs / Op | |
| 110 | + | :--- | :--- | :--- | :--- | :--- | |
| 111 | + | DefaultEncoder DisabledProperties | 18336217 | 298.7 ns | 88 B | 2 | |
| 112 | + | DefaultEncoder EnabledProperties | 18336217 | 334.3 ns | 88 B | 2 | |
| 113 | + | JsonEncoder DisabledProperties | 17974824 | 316.0 ns | 88 B | 2 | |
| 114 | + | JsonEncoder EnabledProperties | 17488896 | 344.2 ns | 88 B | 2 | |
| 115 | + | YamlEncoder DisabledProperties | 17625220 | 342.8 ns | 88 B | 2 | |
| 116 | + | YamlEncoder EnabledProperties | 16005187 | 373.3 ns | 88 B | 2 | |
89 | 117 |
|
90 | | -```bash |
91 | | - git checkout -b feat/your-feature-name |
92 | | - ``` |
| 118 | +## Contributing |
93 | 119 |
|
94 | | -- **Code Style** |
95 | | - - Follow standard Go formatting (`go fmt`) |
96 | | - - Use meaningful variable names |
97 | | - - Add comments for non-obvious code sections |
98 | | - - Write tests for new functionality |
| 120 | +Contributions to this project are very welcome, here's how you can do it: |
99 | 121 |
|
100 | | -- **Testing** |
101 | | - - Run tests: `make test` |
102 | | - - Run benchmarks: `make test-benchmark` |
103 | | - - Ensure test coverage remains high; it can be checked using `make test-coverage` |
| 122 | + 1. Fork the repository |
| 123 | + 2. Clone your fork |
| 124 | + 3. Create a new branch |
| 125 | + ```bash git checkout -b your-feature-name``` |
| 126 | + 4. Local Tests |
| 127 | + Take a look at the [Makefile](./Makefile). |
| 128 | + You can use the commands provided to run `test`, check the `test-coverage` and monitor the library's `benchmarks`. |
104 | 129 |
|
105 | | -## 📝 License |
| 130 | +## License |
106 | 131 |
|
107 | | -MIT License—see [LICENSE](https://mit-license.org/) file for details |
| 132 | +MIT License—see [LICENSE](https://mit-license.org/) file for details |
0 commit comments