From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 188AF1FF168 for ; Tue, 18 Feb 2025 11:07:31 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 73F64855F; Tue, 18 Feb 2025 11:07:27 +0100 (CET) Date: Tue, 18 Feb 2025 11:06:53 +0100 From: Wolfgang Bumiller To: Gabriel Goller Message-ID: References: <20241209104606.263045-2-g.goller@proxmox.com> <5cettqvqg6i6y2cgihynjjirl4vyl6c5l3ewbn4ydhccpgc6ac@aj5yojr624d4> <2cugfnfjfv2robousxhdshdu3rxmyg3bnfdazoyagvn5gglatl@6x4trum24nak> <4iymtwe46mmc7zn6f2erjkfxhal76ma2xy2fh2d4rk2vaqpik4@7n363ok7f5yf> <2yyeufgkcyl3nhkztrynakfbj5q5s35afo4mpkpdowjab2pxam@dufv5c2fpui3> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <2yyeufgkcyl3nhkztrynakfbj5q5s35afo4mpkpdowjab2pxam@dufv5c2fpui3> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.081 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pbs-devel] [PATCH proxmox v2 1/4] log: rename/move init functions X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Cc: Lukas Wagner , pbs-devel@lists.proxmox.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" On Mon, Feb 17, 2025 at 04:21:19PM +0100, Gabriel Goller wrote: > > > > > > > > > > > > > > > I cooked up a simple builder type thingy to build layers: > > > > > > > > > > > > > > > struct LogBuilder { > > > > > global_log_level: LevelFilter, > > > > > layer: Vec< > > > > > Box + 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). Sounds good. > > > > 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. (I think this could be considered a special case, but if its case is covered by the builder that's fine.) > > > > 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. I did say 4 ;-) But okay, the filters are annoying. > > > > * 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. I don't think the nft firewall code (and potential additional new rust-only things we might add in the future) can access this. We have a `proxmox-ve-rs.git` now, but that one won't be used by *pmg*. Anyway, that part is for later. > > > > 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). Yeah. I suppose we can proceed with the builder. It might be good to have the 4 types above summarised in the builder type's doc comments. As for a builder *module* (which you mentioned in an earlier mail) - I *think* API-wise, the builder type itself could very well live (as in be re-exported) at the top level, but implementation wise it could be in its own module for sure, if it makes the code more tidy/organized in your opinion. _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel