mirror of
https://git.proxmox.com/git/proxmox-perl-rs
synced 2025-07-27 11:39:28 +00:00
log: set default log level to 'info', add product specific logging env var
Logging behaviour can be overridden by the {PMG,PVE}_LOG environment variable. This commit also disables styled output and timestamps in log messages, since we usually log to the journal anyway. The log output is configured to match with other log messages in task logs. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
parent
15e7531f3c
commit
d0cab6371a
@ -1,6 +1,14 @@
|
||||
use env_logger::{Builder, Env};
|
||||
use std::io::Write;
|
||||
|
||||
/// Initialize logging. Should only be called once
|
||||
pub fn init() {
|
||||
if let Err(e) = env_logger::try_init() {
|
||||
pub fn init(env_var_name: &str, default_log_level: &str) {
|
||||
if let Err(e) = Builder::from_env(Env::new().filter_or(env_var_name, default_log_level))
|
||||
.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()))
|
||||
.write_style(env_logger::WriteStyle::Never)
|
||||
.format_timestamp(None)
|
||||
.try_init()
|
||||
{
|
||||
eprintln!("could not set up env_logger: {e}");
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,6 @@ mod export {
|
||||
|
||||
#[export]
|
||||
pub fn init() {
|
||||
common::logger::init();
|
||||
common::logger::init("PMG_LOG", "info");
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,6 @@ mod export {
|
||||
|
||||
#[export]
|
||||
pub fn init() {
|
||||
common::logger::init();
|
||||
common::logger::init("PVE_LOG", "info");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user