-
Notifications
You must be signed in to change notification settings - Fork 2
Home
nexlog is a flexible, feature-rich logging library for Zig applications that provides asynchronous logging, file rotation, multiple output handlers, and structured logging capabilities. It's designed to be both powerful and easy to use, making it suitable for applications of any size.
- Multiple Log Levels: Support for debug, info, warning, and error levels
- Asynchronous Logging: High-performance async mode for minimal impact on application performance
- File Rotation: Automatic log file rotation with configurable file size and backup count
- Customizable Handlers: Built-in handlers for console, file, and JSON output, with support for custom handlers
- Rich Metadata: Automatic inclusion of timestamps, thread IDs, file names, and function names
- Structured Logging: JSON output support for machine-readable logs
- Color Support: Terminal color coding for different log levels
- Configurable Buffer Size: Adjustable buffer size for optimal performance
- Context-Based Logging: Support for department/component-specific logging contexts
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 = .{
// 🚧 Nexlog: Actively Developing
// Expect rapid feature growth and frequent changes
// Should look something like this, if you want to fetch the develop branch, just ad `#develop`behind nexlog (without the trailing */*
.url = "git+https://github.com/chrischtel/nexlog/",
.hash = "...",
},
},
}
If you want to fetch a specific release of Nexlog, use the following url format:
zig fetch --save https://github.com/chrischtel/nexlog/archive/v0.4.0.tar.gz
(choose your corresponding release)
Here's a basic example to get you started:
const std = @import("std");
const nexlog = @import("nexlog");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Initialize logger with basic configuration
var builder = nexlog.LogBuilder.init();
try builder
.setMinLevel(.debug)
.enableColors(true)
.enableFileLogging(true, "logs/app.log")
.build(allocator);
defer nexlog.deinit();
// Get the default logger
const logger = nexlog.getDefaultLogger() orelse return error.LoggerNotInitialized;
// Log some messages
logger.info("Application starting", .{}, null);
logger.debug("Debug information", .{}, null);
logger.warn("Warning message", .{}, null);
logger.err("Error occurred", .{}, null);
}
nexlog supports extensive configuration through its builder pattern:
try builder
.setMinLevel(.debug)
.enableColors(true)
.setBufferSize(8192)
.enableFileLogging(true, "logs/app.log")
.setMaxFileSize(5 * 1024 * 1024) // 5MB
.setMaxRotatedFiles(3)
.enableRotation(true)
.enableAsyncMode(true)
.enableMetadata(true)
.build(allocator);
nexlog allows you to create custom log handlers for specialized logging needs. Here's a simple example:
const CustomHandler = struct {
// See custom handler example in documentation
};
For structured logging, nexlog provides built-in JSON support:
var json_handler = try JsonHandler.init(allocator, .{
.min_level = .debug,
.pretty_print = true,
.output_file = "logs/app.json",
});
For more detailed information, check out:
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.
[Add your license information here]