Product Promotion
gittech.site
for different kinds of informations and explorations.
Nexlog: A Logging Library for Zig with Pattern Recognition and Time-Travel
Published at
1 day ago
Main Article
Nexlog
A modern, high-performance logging library for Zig featuring colorized output, file rotation, and comprehensive metadata tracking.
Development will mainly happen on the
develop
branch.
Features
- 🔒 Thread-safe by design
- 🎨 Colorized output for better readability
- 📁 File logging with automatic rotation
- 🔍 Rich metadata tracking (timestamp, thread ID, file, line, function)
- ⚡ High performance with minimal allocations
- 🛠️ Builder pattern for easy configuration
- 🎯 Multiple log levels (trace, debug, info, warn, err, critical)
Quick Start
const std = @import("std");
const nexlog = @import("nexlog");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
// Initialize with builder pattern
var builder = nexlog.LogBuilder.init(); // Create a mutable LogBuilder instance
try builder
.setMinLevel(.debug)
.enableColors(true)
.enableFileLogging(true, "app.log")
.build(allocator);
const logger = nexlog.getDefaultLogger().?;
// Create metadata
const metadata = nexlog.LogMetadata{
.timestamp = std.time.timestamp(),
.thread_id = 0,
.file = @src().file,
.line = @src().line,
.function = @src().fn_name,
};
try logger.log(.info, "Hello {s}!", .{"World"}, metadata);
}
Output Example
[1734269785] [INFO] Application started
[1734269785] [DEBUG] Processing item 42
[1734269785] [WARN] Resource usage high: 85%
[1734269785] [ERROR] Connection failed: timeout
Installation
- Add Nexlog as a dependency in your
build.zig.zon
:
zig fetch --save git+https://github.com/chrischtel/nexlog/
.{
.name = "my-project",
.version = "0.1.0",
.dependencies = .{
.nexlog = .{
.url = "git+https://github.com/chrischtel/nexlog/",
.hash = "...",
},
},
}
- Add to your
build.zig
:
const nexlog = b.dependency("nexlog", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("nexlog", nexlog.module("nexlog"));
Advanced Usage
Configuration Options
const config = nexlog.LogConfig{
.min_level = .info,
.enable_colors = true,
.enable_file_logging = true,
.file_path = "app.log",
.max_file_size = 10 * 1024 * 1024, // 10MB
.enable_rotation = true,
.max_rotated_files = 5,
};
Log Levels
trace
: Finest-grained informationdebug
: Debugging informationinfo
: General informationwarn
: Warning messageserr
: Error messagescritical
: Critical failures
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Building from Source
git clone https://github.com/chrischtel/nexlog.git
cd nexlog
zig build
Run tests:
zig build test
Run examples:
zig build examples
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Thanks to the Zig community for their support and feedback
- Inspired by great logging libraries across different languages
Contact
Your Name - @chrischtel
Project Link: https://github.com/yourusername/nexlog
Made with ❤️ in Zig
Made with ❤️
to provide different kinds of informations and resources.