Chroma Logger is an advanced logging library for Zig projects, designed to bring color and clarity to your application's logging output. Utilizing the Chroma library for colorized output, Chroma Logger enhances the visibility and readability of logs, making debugging and monitoring a breeze.
- Colorized Logging: Leverage the full spectrum of ANSI colors, including 256-color and true color support, to differentiate log levels and messages.
- Flexible Configuration: Control log levels and formatting with ease, allowing for detailed debugging sessions or streamlined production logs.
- Seamless Integration: Designed to work effortlessly within the Zig ecosystem, integrating directly into your Zig build system.
The logger comes in different styles, each with its own use case:
Time based: Logs are colorized based on the time of day.
ChromaLogger.timeBasedLog
Level based: Logs are colorized based on the log level.
ChromaLogger.log
Default based: Logs are displayed in the default color.
ChromaLogger.defaultLog
Ensure you have Zig version 0.12.0-dev.2701+d18f52197 or newer installed on your system.
- Fetch the project using
zig fetch
zig fetch --save https://github.com/adia-dev/chroma-logger-zig/archive/refs/tags/v0.1.0.tar.gzOr manually paste this in your build.zig.zon
.dependencies = .{
// other deps...
.@"chroma-logger" = .{
.url = "https://github.com/adia-dev/chroma-logger-zig/archive/refs/tags/v0.1.0.tar.gz",
.hash = "1220359dd4fb54e367f2aa310b2cf75227aec8f05b254ef93f3bafef34ee2aa39d0b",
},
// ...
},- Build the project:
Using the Zig build system, compile the library and example application:
zig buildThis command compiles the static library and an example executable demonstrating the Chroma Logger in action.
To integrate Chroma Logger into your Zig project, include it as a package in your build.zig file and use it to log messages in various colors and formats:
In your build.zig:
const std = @import("std");
pub fn build(b: *std.Build) void {
...
const chroma_logger_dep = b.dependency("chroma-logger", .{});
...
exe.root_module.addImport("chroma-logger", chroma_logger_dep.module("chroma-logger"));
...
}In your application:
const std = @import("std");
const ChromaLogger = @import("chroma-logger");
// LogFns:
// - ChromaLogger.defaultLog
// - ChromaLogger.timeBasedLog
// - ChromaLogger.log
pub const std_options: std.Options = .{
.logFn = ChromaLogger.log,
.log_level = .debug,
};
pub fn main() !void {
std.log.info("Application started successfully", .{});
std.log.err("Failed to load configuration", .{});
}This example demonstrates how to use Chroma Logger to log messages in various colors and formats. The log function from the ChromaLogger package is used to log messages, and the std.log package is used to log messages in the standard Zig format.
We welcome contributions of all kinds from the community! Whether it's adding new features, improving documentation, or fixing bugs, please feel free to make a pull request.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Chroma - The underlying library providing colorized output for Chroma Logger.