From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 7706ED778 for ; Mon, 21 Aug 2023 13:19:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 57FB51653E for ; Mon, 21 Aug 2023 13:19:43 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 21 Aug 2023 13:19:42 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8FDB742CF9 for ; Mon, 21 Aug 2023 13:19:42 +0200 (CEST) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Mon, 21 Aug 2023 13:19:37 +0200 Message-Id: <20230821111938.110298-1-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.509 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 PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup] api: Outsource the logger initialization to the router 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: , X-List-Received-Date: Mon, 21 Aug 2023 11:19:43 -0000 Instead of manually initializing the `syslog` logger on api/proxy startup, we now call a common function `init_syslog_logger()`, which sets the global logger according to the environment variable passed. Signed-off-by: Gabriel Goller --- src/bin/proxmox-backup-api.rs | 9 ++------- src/bin/proxmox-backup-proxy.rs | 22 +++++----------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index c6c24449..b5bef365 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -8,6 +8,7 @@ use hyper::{Body, StatusCode}; use proxmox_lang::try_block; use proxmox_router::RpcEnvironmentType; +use proxmox_router::init_syslog_logger; use proxmox_sys::fs::CreateOptions; use proxmox_rest_server::{daemon, ApiConfig, RestServer}; @@ -40,13 +41,7 @@ fn get_index() -> Pin> + Send>> { } async fn run() -> Result<(), Error> { - if let Err(err) = syslog::init( - syslog::Facility::LOG_DAEMON, - log::LevelFilter::Info, - Some("proxmox-backup-api"), - ) { - bail!("unable to inititialize syslog - {}", err); - } + init_syslog_logger("proxmox-backup-api", "PBS_LOG", log::LevelFilter::Info)?; config::create_configdir()?; diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index f38a02bd..dce9d3b6 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -7,6 +7,7 @@ use http::request::Parts; use http::Response; use hyper::header; use hyper::{Body, StatusCode}; +use log::log_enabled; use url::form_urlencoded; use openssl::ssl::SslAcceptor; @@ -14,7 +15,7 @@ use serde_json::{json, Value}; use proxmox_lang::try_block; use proxmox_metrics::MetricsData; -use proxmox_router::{RpcEnvironment, RpcEnvironmentType}; +use proxmox_router::{RpcEnvironment, RpcEnvironmentType, init_syslog_logger}; use proxmox_sys::fs::{CreateOptions, FileSystemInformation}; use proxmox_sys::linux::procfs::{Loadavg, ProcFsMemInfo, ProcFsNetDev, ProcFsStat}; use proxmox_sys::logrotate::LogRotate; @@ -181,21 +182,7 @@ async fn get_index_future(env: RestEnvironment, parts: Parts) -> Response } async fn run() -> Result<(), Error> { - // Note: To debug early connection error use - // PROXMOX_DEBUG=1 ./target/release/proxmox-backup-proxy - let debug = std::env::var("PROXMOX_DEBUG").is_ok(); - - if let Err(err) = syslog::init( - syslog::Facility::LOG_DAEMON, - if debug { - log::LevelFilter::Debug - } else { - log::LevelFilter::Info - }, - Some("proxmox-backup-proxy"), - ) { - bail!("unable to inititialize syslog - {err}"); - } + init_syslog_logger("proxmox-backup-proxy", "PBS_LOG", log::LevelFilter::Info)?; proxmox_backup::auth_helpers::setup_auth_context(false); @@ -288,8 +275,9 @@ async fn run() -> Result<(), Error> { Ok(Value::Null) })?; + let connections = proxmox_rest_server::connection::AcceptBuilder::with_acceptor(acceptor) - .debug(debug) + .debug(log_enabled!(log::Level::Debug)) .rate_limiter_lookup(Arc::new(lookup_rate_limiter)) .tcp_keepalive_time(PROXMOX_BACKUP_TCP_KEEPALIVE_TIME); let server = daemon::create_daemon( -- 2.39.2