logs icon indicating copy to clipboard operation
logs copied to clipboard

Selectively set the log level of sources from the CLI

Open MisterDA opened this issue 2 years ago • 2 comments

In my app, I have two sources of logging, Tamino and Papageno. I use logs.cli to setup the logging of my app in a similar fashion as the example. However, in debug mode, Papageno is extremely verbose and I'm much more interested by what Tamino has to say. Could it be possible to extend the API and find some way to set the verbosity of sources from the command-line interface? I can always add code to disable debug output from Papageno, but that's what I was trying to avoid by switching to logs.cli. As I understand the API, logs.cli should not set the verbosity of sources directly, but rather return the verbosity set by the user, so it might be difficult to extend the current API (Logs_cli.level) or come up with a new function. Regarding the actual command-line interface, I think it could look like this:

app --verbosity=debug	# set the debug level for each source
app --verbosity=tamino:debug	# set the verbosity of Tamino to debug. Pamino has the default level.
app --tamino-verbosity=debug	# other syntax proposal
app --verbosity=tamino:debug,pamino:info
app --verbosity=tamino:debug --verbosity=pamino:info
app --tamino-verbosity=debug --pamino-verbosity=info

What style looks the "sanest" to you? I think that only the verbosity flag needs the name expansion.

MisterDA avatar Oct 04 '21 07:10 MisterDA

What style looks the "sanest" to you?

I think I would go with --verbosity=LEVEL[,SRC:LEVEL]…

Did you look around if there may be existing syntax to copycat from (e.g. journalctl or whatever) ?

dbuenzli avatar Oct 04 '21 09:10 dbuenzli

What style looks the "sanest" to you?

I think I would go with --verbosity=LEVEL[,SRC:LEVEL]…

That's quite nice!

Did you look around if there may be existing syntax to copycat from (e.g. journalctl or whatever) ?

journalctl doesn't seem to be able to do that. I can see that it can select multiple sources (-t or -u flags) but the -p flag to select the level is global.

MisterDA avatar Oct 04 '21 11:10 MisterDA