Allocator Usage ​
Logly works with any std.mem.Allocator implementation. Pass your own allocator to Logger.init(allocator) or Logger.initWithConfig(allocator, config).
In most applications, that allocator is std.heap.DebugAllocator.
Basic Usage ​
zig
const std = @import("std");
const logly = @import("logly");
pub fn main() !void {
var gpa = std.heap.DebugAllocator(.{}){};
defer _ = gpa.deinit();
const logger = try logly.Logger.initWithConfig(gpa.allocator(), logly.Config.default());
defer logger.deinit();
try logger.info("Hello from Logly!", @src());
}Using Your Own Arena ​
If your application already uses arena allocation (for example, per-request memory), keep using it. Pass the arena allocator to Logger.initWithConfig:
zig
var gpa = std.heap.DebugAllocator(.{}){};
defer _ = gpa.deinit();
// Application-level arena
var request_arena = std.heap.ArenaAllocator.init(gpa.allocator());
defer request_arena.deinit();
const logger = try logly.Logger.initWithConfig(request_arena.allocator(), logly.Config.default());Thread Pool Integration ​
When using the Thread Pool, each worker thread receives the allocator you pass to Logger.initWithConfig. For parallel logging, ensure thread-safe allocation:
zig
var config = logly.Config.default();
config.thread_pool = .{
.enabled = true,
.thread_count = 4,
};
const logger = try logly.Logger.initWithConfig(allocator, config);Best Practices ​
- Use
DebugAllocatorin development — catches memory leaks and double-frees - Use a dedicated arena for high-throughput logging — reduce malloc overhead
- Keep allocations simple — Logly's internal allocations are designed to be minimal
See Also ​
- Configuration Guide - Full configuration options
- Async Logging - Combine with async for maximum throughput
- Thread Pool - Parallel log processing
