diff --git a/Proxmox/Lib/template.pm b/Proxmox/Lib/template.pm index d7fbbf3..9eb10cf 100644 --- a/Proxmox/Lib/template.pm +++ b/Proxmox/Lib/template.pm @@ -66,6 +66,10 @@ sub bootstrap { $boot->(); } -BEGIN { __PACKAGE__->load(); } +BEGIN { + __PACKAGE__->load(); + __PACKAGE__->bootstrap(); + init(); +} 1; diff --git a/common/src/logger.rs b/common/src/logger.rs new file mode 100644 index 0000000..36dc856 --- /dev/null +++ b/common/src/logger.rs @@ -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}"); + } +} diff --git a/common/src/mod.rs b/common/src/mod.rs index b8b843e..6c86ac0 100644 --- a/common/src/mod.rs +++ b/common/src/mod.rs @@ -1,3 +1,4 @@ pub mod apt; mod calendar_event; +pub mod logger; mod subscription; diff --git a/pmg-rs/Cargo.toml b/pmg-rs/Cargo.toml index 6800f40..2d9ea29 100644 --- a/pmg-rs/Cargo.toml +++ b/pmg-rs/Cargo.toml @@ -20,6 +20,7 @@ crate-type = [ "cdylib" ] [dependencies] anyhow = "1.0" +env_logger = "0.9" hex = "0.4" http = "0.2.7" libc = "0.2" diff --git a/pmg-rs/src/lib.rs b/pmg-rs/src/lib.rs index af89416..5914bc9 100644 --- a/pmg-rs/src/lib.rs +++ b/pmg-rs/src/lib.rs @@ -5,3 +5,13 @@ pub mod acme; pub mod apt; pub mod csr; pub mod tfa; + +#[perlmod::package(name = "Proxmox::Lib::PMG", lib = "pmg_rs")] +mod export { + use crate::common; + + #[export] + pub fn init() { + common::logger::init(); + } +} diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml index aa32aeb..6c921c4 100644 --- a/pve-rs/Cargo.toml +++ b/pve-rs/Cargo.toml @@ -18,6 +18,7 @@ crate-type = [ "cdylib" ] anyhow = "1.0" base32 = "0.4" base64 = "0.13" +env_logger = "0.9" hex = "0.4" http = "0.2.7" libc = "0.2" diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs index 562a4d4..671aad0 100644 --- a/pve-rs/src/lib.rs +++ b/pve-rs/src/lib.rs @@ -7,3 +7,13 @@ pub mod apt; pub mod openid; pub mod resource_scheduling; pub mod tfa; + +#[perlmod::package(name = "Proxmox::Lib::PVE", lib = "pve_rs")] +mod export { + use crate::common; + + #[export] + pub fn init() { + common::logger::init(); + } +}