log: use new builder initializer

Use new logger builder to initialize the logging in each component.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
This commit is contained in:
Gabriel Goller 2025-02-18 17:16:40 +01:00 committed by Wolfgang Bumiller
parent f74978572b
commit d99c481596
12 changed files with 51 additions and 29 deletions

View File

@ -15,7 +15,6 @@
use anyhow::{bail, Error};
use serde_json::Value;
use proxmox_log::init_cli_logger;
use proxmox_router::cli::*;
use proxmox_router::RpcEnvironment;
use proxmox_schema::{api, ArraySchema, IntegerSchema, Schema, StringSchema};
@ -800,7 +799,9 @@ fn options(
}
fn main() -> Result<(), Error> {
init_cli_logger("PBS_LOG", proxmox_log::LevelFilter::INFO)?;
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.stderr()
.init()?;
let uid = nix::unistd::Uid::current();

View File

@ -16,7 +16,6 @@ use std::fs::File;
use anyhow::{bail, Error};
use serde_json::Value;
use proxmox_log::init_cli_logger;
use proxmox_router::cli::*;
use proxmox_router::RpcEnvironment;
use proxmox_schema::api;
@ -388,7 +387,9 @@ fn scan(param: Value) -> Result<(), Error> {
}
fn main() -> Result<(), Error> {
init_cli_logger("PBS_LOG", proxmox_log::LevelFilter::INFO)?;
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.stderr()
.init()?;
let uid = nix::unistd::Uid::current();

View File

@ -16,7 +16,6 @@ use xdg::BaseDirectories;
use pathpatterns::{MatchEntry, MatchType, PatternFlag};
use proxmox_async::blocking::TokioWriterAdapter;
use proxmox_io::StdChannelWriter;
use proxmox_log::init_cli_logger;
use proxmox_router::{cli::*, ApiMethod, RpcEnvironment};
use proxmox_schema::api;
use proxmox_sys::fs::{file_get_json, image_size, replace_file, CreateOptions};
@ -1969,7 +1968,10 @@ impl ReadAt for BufferedDynamicReadAt {
fn main() {
pbs_tools::setup_libc_malloc_opts();
init_cli_logger("PBS_LOG", proxmox_log::LevelFilter::INFO).expect("failed to initiate logger");
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.stderr()
.init()
.expect("failed to initiate logger");
let backup_cmd_def = CliCommand::new(&API_METHOD_CREATE_BACKUP)
.arg_param(&["backupspec"])

View File

@ -10,7 +10,6 @@ use serde_json::{json, Value};
use tokio::io::AsyncWriteExt;
use proxmox_compression::zstd::ZstdEncoder;
use proxmox_log::init_cli_logger;
use proxmox_router::cli::{
complete_file_name, default_table_format_options, format_and_print_result_full,
get_output_format, run_cli_command, CliCommand, CliCommandMap, CliEnvironment, ColumnConfig,
@ -629,7 +628,11 @@ fn main() {
true => proxmox_log::LevelFilter::DEBUG,
false => proxmox_log::LevelFilter::INFO,
};
init_cli_logger("PBS_LOG", loglevel).expect("failed to initiate logger");
proxmox_log::Logger::from_env("PBS_LOG", loglevel)
.stderr()
.init()
.expect("failed to initiate logger");
let list_cmd_def = CliCommand::new(&API_METHOD_LIST)
.arg_param(&["snapshot", "path"])

View File

@ -22,7 +22,7 @@ use pbs_client::pxar::{
use pxar::EntryKind;
use proxmox_human_byte::HumanByte;
use proxmox_log::{debug, enabled, error, init_cli_logger, Level};
use proxmox_log::{debug, enabled, error, Level};
use proxmox_router::cli::*;
use proxmox_schema::api;
@ -574,7 +574,10 @@ fn dump_archive(archive: String, payload_input: Option<String>) -> Result<(), Er
}
fn main() {
init_cli_logger("PXAR_LOG", proxmox_log::LevelFilter::INFO).expect("failed to initiate logger");
proxmox_log::Logger::from_env("PXAR_LOG", proxmox_log::LevelFilter::INFO)
.stderr()
.init()
.expect("failed to initiate logger");
let cmd_def = CliCommandMap::new()
.insert(

View File

@ -8,7 +8,6 @@ use hyper::{Body, StatusCode};
use tracing::level_filters::LevelFilter;
use proxmox_lang::try_block;
use proxmox_log::init_logger;
use proxmox_rest_server::{ApiConfig, RestServer};
use proxmox_router::RpcEnvironmentType;
use proxmox_sys::fs::CreateOptions;
@ -41,7 +40,10 @@ fn get_index() -> Pin<Box<dyn Future<Output = Response<Body>> + Send>> {
}
async fn run() -> Result<(), Error> {
init_logger("PBS_LOG", LevelFilter::INFO)?;
proxmox_log::Logger::from_env("PBS_LOG", LevelFilter::INFO)
.journald_on_no_workertask()
.tasklog_pbs()
.init()?;
config::create_configdir()?;

View File

@ -1,4 +1,3 @@
use proxmox_log::init_cli_logger;
use proxmox_router::{
cli::{run_cli_command, CliCommandMap, CliEnvironment},
RpcEnvironment,
@ -8,7 +7,10 @@ mod proxmox_backup_debug;
use proxmox_backup_debug::*;
fn main() {
init_cli_logger("PBS_LOG", proxmox_log::LevelFilter::INFO).expect("failed to initiate logger");
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.stderr()
.init()
.expect("failed to initiate logger");
let cmd_def = CliCommandMap::new()
.insert("inspect", inspect::inspect_commands())

View File

@ -3,7 +3,6 @@ use std::io::{self, Write};
use std::str::FromStr;
use anyhow::{format_err, Error};
use proxmox_log::init_cli_logger;
use serde_json::{json, Value};
use proxmox_router::{cli::*, RpcEnvironment};
@ -618,7 +617,12 @@ async fn get_versions(verbose: bool, param: Value) -> Result<Value, Error> {
}
async fn run() -> Result<(), Error> {
init_cli_logger("PBS_LOG", proxmox_log::LevelFilter::INFO)?;
// We need to use the tasklog logger here as well, because the proxmox-backup-manager can and
// will directly execute workertasks.
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.stderr_on_no_workertask()
.tasklog_pbs()
.init()?;
proxmox_backup::server::notifications::init()?;
let cmd_def = CliCommandMap::new()

View File

@ -16,7 +16,6 @@ use openssl::ssl::SslAcceptor;
use serde_json::{json, Value};
use proxmox_lang::try_block;
use proxmox_log::init_logger;
use proxmox_router::{RpcEnvironment, RpcEnvironmentType};
use proxmox_sys::fs::CreateOptions;
use proxmox_sys::logrotate::LogRotate;
@ -179,7 +178,10 @@ async fn get_index_future(env: RestEnvironment, parts: Parts) -> Response<Body>
}
async fn run() -> Result<(), Error> {
init_logger("PBS_LOG", LevelFilter::INFO)?;
proxmox_log::Logger::from_env("PBS_LOG", LevelFilter::INFO)
.journald_on_no_workertask()
.tasklog_pbs()
.init()?;
proxmox_backup::auth_helpers::setup_auth_context(false);
proxmox_backup::server::notifications::init()?;

View File

@ -110,13 +110,12 @@ async fn run(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
fn main() {
proxmox_backup::tools::setup_safe_path_env();
if let Err(err) = syslog::init(
syslog::Facility::LOG_DAEMON,
log::LevelFilter::Info,
Some("proxmox-daily-update"),
) {
eprintln!("unable to initialize syslog - {err}");
}
// We need to use the tasklog layer here because we call a workertask.
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.journald_on_no_workertask()
.tasklog_pbs()
.init()
.expect("unable to initialize logger");
let mut rpcenv = CliEnvironment::new();
rpcenv.set_auth_id(Some(String::from("root@pam")));

View File

@ -5,7 +5,6 @@ use serde_json::{json, Value};
use proxmox_human_byte::HumanByte;
use proxmox_io::ReadExt;
use proxmox_log::init_cli_logger;
use proxmox_router::cli::*;
use proxmox_router::RpcEnvironment;
use proxmox_schema::api;
@ -998,7 +997,10 @@ async fn catalog_media(mut param: Value) -> Result<(), Error> {
}
fn main() {
init_cli_logger("PBS_LOG", proxmox_log::LevelFilter::INFO).expect("failed to initiate logger");
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.stderr()
.init()
.expect("failed to initiate logger");
let cmd_def = CliCommandMap::new()
.insert(

View File

@ -10,7 +10,6 @@ use pbs_tape::sg_tape::SgTape;
use proxmox_backup::tape::encryption_keys::load_key;
use serde_json::Value;
use proxmox_log::init_cli_logger;
use proxmox_router::{cli::*, RpcEnvironment};
use proxmox_schema::api;
use proxmox_uuid::Uuid;
@ -125,7 +124,9 @@ fn set_encryption(
}
fn main() -> Result<(), Error> {
init_cli_logger("PBS_LOG", proxmox_log::LevelFilter::INFO)?;
proxmox_log::Logger::from_env("PBS_LOG", proxmox_log::LevelFilter::INFO)
.stderr()
.init()?;
// check if we are user root or backup
let backup_uid = pbs_config::backup_user()?.uid;