cli: allow setting log level with '-l' flag

This commit is contained in:
Isaac Freund 2020-06-17 02:01:07 +02:00
parent d74323bbbf
commit 0efc04508b
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
2 changed files with 22 additions and 4 deletions

View file

@ -5,7 +5,7 @@ river - dynamic tiling Wayland compositor
# SYNOPSIS
*river* [*-c* _shell_command_]
*river* [*-c* _shell_command_] [*-l* _log_level_]
# DESCRIPTION
@ -20,6 +20,11 @@ bspwm based on wlroots and written in Zig.
*riverctl*(1) and autostart programs. Make sure the script is
executable.
*-l* _log_level_
Set the log level of river to a value from 0 to 7 with 0 being the
least verbose and 7 being the most verbose. The default log level of
release-safe builds is 5.
# CONFIGURATION
View border width, gap sizes, and programs which should float are

View file

@ -28,6 +28,7 @@ const usage: []const u8 =
\\
\\ -h Print this help message and exit.
\\ -c <command> Run `sh -c <command>` on startup.
\\ -l <level> Set the log level to a value from 0 to 7.
\\
;
@ -46,9 +47,15 @@ pub fn main() !void {
if (it.nextPosix()) |command| {
startup_command = command;
} else {
const stderr = std.io.getStdErr().outStream();
try stderr.print("Error: flag '-c' requires exactly one argument\n", .{});
std.os.exit(1);
printErrorExit("Error: flag '-c' requires exactly one argument", .{});
}
} else if (std.mem.eql(u8, arg, "-l")) {
if (it.nextPosix()) |level_str| {
const level = std.fmt.parseInt(u3, level_str, 10) catch
printErrorExit("Error: invalid log level '{}'", .{level_str});
log.level = @intToEnum(log.Level, level);
} else {
printErrorExit("Error: flag '-l' requires exactly one argument", .{});
}
} else {
const stderr = std.io.getStdErr().outStream();
@ -81,3 +88,9 @@ pub fn main() !void {
log.info(.server, "shutting down", .{});
}
fn printErrorExit(comptime format: []const u8, args: var) noreturn {
const stderr = std.io.getStdErr().outStream();
stderr.print(format ++ "\n", args) catch std.os.exit(1);
std.os.exit(1);
}