allow more logging control
This commit is contained in:
parent
aee9b34ec7
commit
74d9440bec
1 changed files with 30 additions and 1 deletions
31
src/main.zig
31
src/main.zig
|
@ -8,6 +8,24 @@ const Args = struct {
|
||||||
syncthing_url: ?[]const u8 = null,
|
syncthing_url: ?[]const u8 = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const std_options: std.Options = .{
|
||||||
|
.logFn = logFn,
|
||||||
|
.log_level = .debug,
|
||||||
|
};
|
||||||
|
|
||||||
|
var log_level = std.log.default_level;
|
||||||
|
|
||||||
|
fn logFn(
|
||||||
|
comptime message_level: std.log.Level,
|
||||||
|
comptime scope: @TypeOf(.enum_literal),
|
||||||
|
comptime format: []const u8,
|
||||||
|
args: anytype,
|
||||||
|
) void {
|
||||||
|
if (@intFromEnum(message_level) <= @intFromEnum(log_level)) {
|
||||||
|
std.log.defaultLog(message_level, scope, format, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() !u8 {
|
pub fn main() !u8 {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}).init;
|
var gpa = std.heap.GeneralPurposeAllocator(.{}).init;
|
||||||
defer _ = gpa.deinit();
|
defer _ = gpa.deinit();
|
||||||
|
@ -104,6 +122,8 @@ fn parseArgs(allocator: std.mem.Allocator) !Args {
|
||||||
std.debug.print("Error: --url requires a URL argument\n", .{});
|
std.debug.print("Error: --url requires a URL argument\n", .{});
|
||||||
std.process.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
|
} else if (std.mem.eql(u8, arg, "-v")) {
|
||||||
|
moreVerbose();
|
||||||
} else if (std.mem.eql(u8, arg, "--help")) {
|
} else if (std.mem.eql(u8, arg, "--help")) {
|
||||||
printUsage();
|
printUsage();
|
||||||
std.process.exit(0);
|
std.process.exit(0);
|
||||||
|
@ -113,6 +133,14 @@ fn parseArgs(allocator: std.mem.Allocator) !Args {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn moreVerbose() void {
|
||||||
|
log_level = switch (log_level) {
|
||||||
|
.info, .debug => .debug,
|
||||||
|
.warn => .info,
|
||||||
|
.err => .warn,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const FileType = enum {
|
const FileType = enum {
|
||||||
json,
|
json,
|
||||||
zon,
|
zon,
|
||||||
|
@ -145,7 +173,8 @@ fn printUsage() void {
|
||||||
\\Options:
|
\\Options:
|
||||||
\\ --config <path> Path to config file (default: config.json)
|
\\ --config <path> Path to config file (default: config.json)
|
||||||
\\ --url <url> Override Syncthing URL from config
|
\\ --url <url> Override Syncthing URL from config
|
||||||
\\ --help Show this help message
|
\\ -v Increase logging verbosity (can be used multiple times)
|
||||||
|
\\ --help Show this help message
|
||||||
\\
|
\\
|
||||||
\\ST_EVENTS_AUTH environment variable must contain the auth token for
|
\\ST_EVENTS_AUTH environment variable must contain the auth token for
|
||||||
\\syncthing. This can be found in the syncthing UI by clicking Actions,
|
\\syncthing. This can be found in the syncthing UI by clicking Actions,
|
||||||
|
|
Loading…
Add table
Reference in a new issue