all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cc: Lukas Wagner <l.wagner@proxmox.com>, pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox v2 1/4] log: rename/move init functions
Date: Mon, 17 Feb 2025 16:21:19 +0100	[thread overview]
Message-ID: <2yyeufgkcyl3nhkztrynakfbj5q5s35afo4mpkpdowjab2pxam@dufv5c2fpui3> (raw)
In-Reply-To: <sb6fqudqt4jrewfugeafluk2czmzh34zkzgzlg4aadtuhinsle@ds3vqwr2wypo>

>> > > <snip>
>> > >
>> > > I cooked up a simple builder type thingy to build layers:
>> > >
>> > >
>> > >     struct LogBuilder {
>> > >         global_log_level: LevelFilter,
>> > >         layer: Vec<
>> > >             Box<dyn tracing_subscriber::Layer<tracing_subscriber::Registry> + Send + Sync + 'static>,
>> > >         >,
>> > >     }
>> > >
>> > >
>> > > And the implementation:
>> > >
>> > >     impl LogBuilder {
>> > >         pub fn from_env(env_var: &str, default_log_level: LevelFilter) -> LogBuilder {
>> > >             let log_level = get_env_variable(env_var, default_log_level);
>> > >             LogBuilder {
>> > >                 global_log_level: log_level,
>> > >                 layer: vec![],
>> > >             }
>> > >         }
>> > >
>> > >         pub fn journald_or_stderr(mut self) -> LogBuilder {
>> > >             self.layer.push(
>> > >                 journald_or_stderr_layer()
>> > >                     .with_filter(self.global_log_level)
>> > >                     .boxed(),
>> > >             );
>> > >             self
>> > >         }
>> > >
>> > >         pub fn journald_or_stderr_on_logcontext_and_error(mut self) -> LogBuilder {
>> > >             self.layer.push(
>> > >                 journald_or_stderr_layer()
>> > >                     .with_filter(filter_fn(|metadata| {
>> > >                         !LogContext::exists() || *metadata.level() == Level::ERROR
>> > >                     }))
>> > >                     .with_filter(self.global_log_level)
>> > >                     .boxed(),
>> > >             );
>> > >             self
>> > >         }
>> > >
>> > >         //...
>> > >
>> > >         pub fn init(self) -> Result<(), anyhow::Error> {
>> > >             let registry = tracing_subscriber::registry().with(self.layer);
>> > >             tracing::subscriber::set_global_default(registry)?;
>> > >
>> > >             LogTracer::init_with_filter(self.global_log_level.as_log())?;
>> > >             Ok(())
>> > >         }
>> > >     }
>> > >
>> > > We could place this in a new builder module and then have the
>> > > product-specific functions (e.g. init_pve_log, init_perlmod_log,
>> > > init_pbs_log, etc.) in the init module.
>> > >
>> > > What do you think?
>> >
>> > Hmmm...
>> > Those names are a bit long, and still as specific as before, so I'm not
>> > sure we win a lot either way.
>> >
>> > I'm wondering - if we really have so many specific cases - do we really
>> > need them implemented in this crate, rather than where they are used?
>> > How many different types of logging layers do we have and where atm?
>>
>> We currently have:
>>  1) journald (with stderr fallback)
>
>=> builder.journald_logging()
>
>(the fallback could just be implied, or do we ever not want that?)

true, I don't think we want to fail anywhere if there is no journald
anyway.

>>  2) stderr
>
>=> builder.stderr_logging()
>
>>  3) stderr (with pve formatting)
>
>=> builder.pve_logging() (#[cfg(feature = "pve")]?)

Maybe stderr_pve_logging? I'd like to mention 'stderr' somewhere in the
case we add some different pve-format logging (e.g. pve-tasklog).

>>  4) pbs tasklog
>^ I assume (4) is the "tasklog-or-journald" case?
>Not sure where (1) is really the right choice.
>
>Does (4) exist anywhere other than in the API daemons?
>
>=> builder.task_logging()
>
>(the journal-if-not-in-task part could be implied - or do we ever need
>to combine the tasklog part differently?)

Yes, in the proxmox-backup-manager. There we use stderr for all the
normal logs and the tasklogger for when we a task is started.

>> But the problem is we have different combinations and filters as well:
>> journald and stderr (perlmod), stderr and pbs tasklog (but only when we
>> are in a tasklog or when the level is error) (pbs-client), etc.
>
>^ Why is "pbs-client" the example here? IMO this sounds like the API
>daemons. The pbs-client *CLI* tool certainly should just log to stderr,
>and the "crate" otherwise doesn't decide this.

Oops, my bad I meant the proxmox-backup-manager.

>> The logging gets initiated in:
>
>(list below is reordered)
>
>>  * pbs proxy daemon
>>  * pbs api daemon
>
>^ API daemons - so those are case (4) - are they different from one
>another?

Nope, this is case 4. (To be exact case 1 + 4, journald + tasklog.)
Also you need to add filters here, this isn't just a "print everything
to journald", we only print to journald when the level is error or we
are *not* in a tasklog.

>>  * pbs proxmox-file-restore
>
>^ The VM side? Not sure what it needs, but seems special-enough to have
>its own code, unless we just log to the journal anyway

As far as I remember this one should print to stderr only. (This is
wrong in this patch.)

>>  * pbs tape pmt
>>  * pbs tape pmtx
>>  * pbs client
>>  * pbs pxar
>>  * pbs proxmox-backup-debug
>>  * pbs proxmox-backup-manager
>>  * pbs proxmox-backup-tape
>>  * pbs sg-tape-cmd
>
>^ IIRC all of these are CLI tools and should therefore all be case (2) -
>although I don't know about how the tape stuff works.
>If they do anything else, it would be good to know why and have this
>documented either in proxmox-log or in their logging-init functions.

All except the proxmox-backup-manager as far as I can see, because that
one starts pbs tasks directly.

>>  * pbs proxmox-daily-update
>
>The 'daily-update' may be a special case and could use the journal
>directly, but may as well be stderr->journald via its `.service`.
>But, yeah, obviously it would make actual tracing/debugging easier with
>a proper journald-logger here. So another user of case (1).

Agree.

>>  * perlmod
>^ For the lack of a better place (as pve, pmg and nftables code probably
>all want to share it), having this as a special function in proxmox-log
>makes some sense I suppose (but could be feature-guarded).

There is already a shared common::init_logger function in perlmod I think.

>> Exposing the builder directly without any helper functions would be fine
>> as well I reckon. The downside is that the initiation gets more
>> "complicated", e.g. (the pbs daemon):
>>
>>     LogBuilder::from_env("PBS_LOG", LevelFilter::INFO)
>>         .journald_on_no_tasklog_or_error()
>>         .tasklog().init()?;
>
>So yes this is probably okay to have, but I really don't think we need
>these huge names - like I said, it doesn't make sense to me that
>`.tasklog()` should be combined with anything other than this exact one
>other thing anyway, so the middle line there could just be left out IMO.

See above.
Also either we use a helper function which does everything for us (e.g.
init_perlmod_logger, init_journald_and_tasklog) or we use the builder
where we *need* to mention every layer separately. Otherwise you have different
builder functions, some which add a single layer and others that add
multiple layers + magic (which IMO is a mess).




_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  reply	other threads:[~2025-02-17 15:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-09 10:46 [pbs-devel] [PATCH proxmox{, -backup, -perl-rs} v2 0/4] Rename/Move logging init helper Gabriel Goller
2024-12-09 10:46 ` [pbs-devel] [PATCH proxmox v2 1/4] log: rename/move init functions Gabriel Goller
2025-02-10 14:37   ` Wolfgang Bumiller
2025-02-10 16:42     ` Gabriel Goller
2025-02-11  9:22       ` Wolfgang Bumiller
2025-02-11  9:28         ` Wolfgang Bumiller
2025-02-17 13:08           ` Gabriel Goller
2025-02-17 13:38             ` Wolfgang Bumiller
2025-02-17 14:12               ` Gabriel Goller
2025-02-17 14:51                 ` Wolfgang Bumiller
2025-02-17 15:21                   ` Gabriel Goller [this message]
2025-02-18 10:06                     ` Wolfgang Bumiller
2025-02-18 16:15                       ` Gabriel Goller
2025-02-11  9:31         ` Gabriel Goller
2024-12-09 10:46 ` [pbs-devel] [PATCH proxmox v2 2/4] log: add logger for perlmod crates Gabriel Goller
2024-12-09 10:46 ` [pbs-devel] [PATCH proxmox-backup v2 3/4] log: use new init functions Gabriel Goller
2024-12-09 10:46 ` [pbs-devel] [PATCH proxmox-perl-rs v2 4/4] log: use new init function, print to stderr and journald Gabriel Goller
2025-01-09 10:09 ` [pbs-devel] [PATCH proxmox{, -backup, -perl-rs} v2 0/4] Rename/Move logging init helper Lukas Wagner
2025-01-14  8:43 ` Gabriel Goller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2yyeufgkcyl3nhkztrynakfbj5q5s35afo4mpkpdowjab2pxam@dufv5c2fpui3 \
    --to=g.goller@proxmox.com \
    --cc=l.wagner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=w.bumiller@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal