-
Notifications
You must be signed in to change notification settings - Fork 286
add --verbose option #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add --verbose option #332
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,14 @@ pub const websocket_blocking = true; | |
|
|
||
| const log = std.log.scoped(.cli); | ||
|
|
||
| pub const std_options = .{ | ||
| // Set the log level to info | ||
| .log_level = .debug, | ||
|
|
||
| // Define logFn to override the std implementation | ||
| .logFn = logFn, | ||
| }; | ||
|
|
||
| const usage = | ||
| \\usage: {s} [options] [URL] | ||
| \\ | ||
|
|
@@ -49,6 +57,7 @@ const usage = | |
| \\ * otherwhise the browser starts a CDP server | ||
| \\ | ||
| \\ -h, --help Print this help message and exit. | ||
| \\ --verbose Display all logs. By default only info, warn and err levels are displayed. | ||
| \\ --host Host of the CDP server (default "127.0.0.1") | ||
| \\ --port Port of the CDP server (default "9222") | ||
| \\ --timeout Timeout for incoming connections of the CDP server (in seconds, default "3") | ||
|
|
@@ -110,6 +119,10 @@ const CliMode = union(CliModeTag) { | |
| if (std.mem.eql(u8, "-h", opt) or std.mem.eql(u8, "--help", opt)) { | ||
| return printUsageExit(execname, 0); | ||
| } | ||
| if (std.mem.eql(u8, "--verbose", opt)) { | ||
| verbose = true; | ||
| continue; | ||
| } | ||
| if (std.mem.eql(u8, "--dump", opt)) { | ||
| _fetch.dump = true; | ||
| continue; | ||
|
|
@@ -334,3 +347,18 @@ pub fn main() !void { | |
| }, | ||
| } | ||
| } | ||
|
|
||
| var verbose: bool = builtin.mode == .Debug; // In debug mode, force verbose. | ||
| fn logFn( | ||
| comptime level: std.log.Level, | ||
| comptime scope: @Type(.EnumLiteral), | ||
| comptime format: []const u8, | ||
| args: anytype, | ||
| ) void { | ||
| if (!verbose) { | ||
| // hide all messages with level greater of equal to debug level. | ||
| if (@intFromEnum(level) >= @intFromEnum(std.log.Level.debug)) return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But Since we filter here, I do prefer the |
||
| } | ||
| // default std log function. | ||
| std.log.defaultLog(level, scope, format, args); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of this global variable but I guess it's not possible to do without, at least if we want to keep using the std lib log function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think have a global var in the
main.zigis not perfect, but ok.