Skip to content

Commit ab4973a

Browse files
committed
add --verbose option
1 parent 3b018e2 commit ab4973a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ pub const websocket_blocking = true;
4040

4141
const log = std.log.scoped(.cli);
4242

43+
pub const std_options = .{
44+
// Set the log level to info
45+
.log_level = .debug,
46+
47+
// Define logFn to override the std implementation
48+
.logFn = logFn,
49+
};
50+
4351
const usage =
4452
\\usage: {s} [options] [URL]
4553
\\
@@ -49,6 +57,7 @@ const usage =
4957
\\ * otherwhise the browser starts a CDP server
5058
\\
5159
\\ -h, --help Print this help message and exit.
60+
\\ --verbose Display all logs. By default only info, warn and err levels are displayed.
5261
\\ --host Host of the CDP server (default "127.0.0.1")
5362
\\ --port Port of the CDP server (default "9222")
5463
\\ --timeout Timeout for incoming connections of the CDP server (in seconds, default "3")
@@ -110,6 +119,10 @@ const CliMode = union(CliModeTag) {
110119
if (std.mem.eql(u8, "-h", opt) or std.mem.eql(u8, "--help", opt)) {
111120
return printUsageExit(execname, 0);
112121
}
122+
if (std.mem.eql(u8, "--verbose", opt)) {
123+
verbose = true;
124+
continue;
125+
}
113126
if (std.mem.eql(u8, "--dump", opt)) {
114127
_fetch.dump = true;
115128
continue;
@@ -334,3 +347,18 @@ pub fn main() !void {
334347
},
335348
}
336349
}
350+
351+
var verbose: bool = builtin.mode == .Debug; // In debug mode, force verbose.
352+
fn logFn(
353+
comptime level: std.log.Level,
354+
comptime scope: @Type(.EnumLiteral),
355+
comptime format: []const u8,
356+
args: anytype,
357+
) void {
358+
if (!verbose) {
359+
// hide all messages with level greater of equal to debug level.
360+
if (@intFromEnum(level) >= @intFromEnum(std.log.Level.debug)) return;
361+
}
362+
// default std log function.
363+
std.log.defaultLog(level, scope, format, args);
364+
}

0 commit comments

Comments
 (0)