forked from Proxmox/proxmox-perl-rs
initialize logging when shared library is loaded
This commit sets up logging by hooking into module loading/bootstraping process to call a new `init` function exported by the `Proxmox::Lib::{PVE,PMG}` module, which initializes `env_logger` with its default settings. This allows us to use `log::*` macros from Rust code. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
parent
f6b244dfb3
commit
c7c3940718
@ -66,6 +66,10 @@ sub bootstrap {
|
|||||||
$boot->();
|
$boot->();
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN { __PACKAGE__->load(); }
|
BEGIN {
|
||||||
|
__PACKAGE__->load();
|
||||||
|
__PACKAGE__->bootstrap();
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
6
common/src/logger.rs
Normal file
6
common/src/logger.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/// Initialize logging. Should only be called once
|
||||||
|
pub fn init() {
|
||||||
|
if let Err(e) = env_logger::try_init() {
|
||||||
|
eprintln!("could not set up env_logger: {e}");
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
pub mod apt;
|
pub mod apt;
|
||||||
mod calendar_event;
|
mod calendar_event;
|
||||||
|
pub mod logger;
|
||||||
mod subscription;
|
mod subscription;
|
||||||
|
@ -20,6 +20,7 @@ crate-type = [ "cdylib" ]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
env_logger = "0.9"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
http = "0.2.7"
|
http = "0.2.7"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
@ -5,3 +5,13 @@ pub mod acme;
|
|||||||
pub mod apt;
|
pub mod apt;
|
||||||
pub mod csr;
|
pub mod csr;
|
||||||
pub mod tfa;
|
pub mod tfa;
|
||||||
|
|
||||||
|
#[perlmod::package(name = "Proxmox::Lib::PMG", lib = "pmg_rs")]
|
||||||
|
mod export {
|
||||||
|
use crate::common;
|
||||||
|
|
||||||
|
#[export]
|
||||||
|
pub fn init() {
|
||||||
|
common::logger::init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ crate-type = [ "cdylib" ]
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
base32 = "0.4"
|
base32 = "0.4"
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
|
env_logger = "0.9"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
http = "0.2.7"
|
http = "0.2.7"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
@ -7,3 +7,13 @@ pub mod apt;
|
|||||||
pub mod openid;
|
pub mod openid;
|
||||||
pub mod resource_scheduling;
|
pub mod resource_scheduling;
|
||||||
pub mod tfa;
|
pub mod tfa;
|
||||||
|
|
||||||
|
#[perlmod::package(name = "Proxmox::Lib::PVE", lib = "pve_rs")]
|
||||||
|
mod export {
|
||||||
|
use crate::common;
|
||||||
|
|
||||||
|
#[export]
|
||||||
|
pub fn init() {
|
||||||
|
common::logger::init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user