all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] api: Outsource the logger initialization to the router
Date: Mon, 21 Aug 2023 13:19:37 +0200	[thread overview]
Message-ID: <20230821111938.110298-1-g.goller@proxmox.com> (raw)

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





             reply	other threads:[~2023-08-21 11:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21 11:19 Gabriel Goller [this message]
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

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=20230821111938.110298-1-g.goller@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.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