public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] api: Outsource the logger initialization to the router
@ 2023-08-21 11:19 Gabriel Goller
  2023-08-21 11:19 ` [pbs-devel] [PATCH proxmox] router: Added `init_syslog_logger()` function Gabriel Goller
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Gabriel Goller @ 2023-08-21 11:19 UTC (permalink / raw)
  To: pbs-devel

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 <g.goller@proxmox.com>
---
 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<Box<dyn Future<Output = Response<Body>> + 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<Body>
 }
 
 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





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-09-29 11:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21 11:19 [pbs-devel] [PATCH proxmox-backup] api: Outsource the logger initialization to the router Gabriel Goller
2023-08-21 11:19 ` [pbs-devel] [PATCH proxmox] router: Added `init_syslog_logger()` function Gabriel Goller
2023-09-29  8:47 ` [pbs-devel] [PATCH proxmox-backup] api: Outsource the logger initialization to the router Gabriel Goller
2023-09-29  9:35 ` Dominik Csapak
2023-09-29  9:49   ` Wolfgang Bumiller
2023-09-29 10:23     ` Dominik Csapak
2023-09-29 11:09     ` Gabriel Goller
2023-09-29 11:46       ` Wolfgang Bumiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal