Add a log utility
This commit is contained in:
parent
d0bfa7bb01
commit
5e84d69237
2 changed files with 30 additions and 2 deletions
24
src/log.zig
Normal file
24
src/log.zig
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub const Log = enum {
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
Silent,
|
||||||
|
Error,
|
||||||
|
Info,
|
||||||
|
Debug,
|
||||||
|
|
||||||
|
var verbosity = Self.Error;
|
||||||
|
|
||||||
|
pub fn init(_verbosity: Self) void {
|
||||||
|
verbosity = _verbosity;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log(level: Self, comptime format: []const u8, args: var) void {
|
||||||
|
if (@enumToInt(level) <= @enumToInt(verbosity)) {
|
||||||
|
// TODO: log the time since start in the same format as wlroots
|
||||||
|
// TODO: use color if logging to a tty
|
||||||
|
std.debug.warn("[{}] " ++ format ++ "\n", .{@tagName(level)} ++ args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,12 +1,14 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const Log = @import("log.zig").Log;
|
||||||
|
|
||||||
const Server = @import("server.zig").Server;
|
const Server = @import("server.zig").Server;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
std.debug.warn("Starting up.\n", .{});
|
Log.init(Log.Debug);
|
||||||
|
c.wlr_log_init(c.enum_wlr_log_importance.WLR_ERROR, null);
|
||||||
|
|
||||||
c.wlr_log_init(c.enum_wlr_log_importance.WLR_DEBUG, null);
|
Log.Info.log("Initializing server", .{});
|
||||||
|
|
||||||
var server: Server = undefined;
|
var server: Server = undefined;
|
||||||
try server.init(std.heap.c_allocator);
|
try server.init(std.heap.c_allocator);
|
||||||
|
@ -14,5 +16,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
try server.start();
|
try server.start();
|
||||||
|
|
||||||
|
Log.Info.log("Running server...", .{});
|
||||||
|
|
||||||
server.run();
|
server.run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue