Skip to content

Commit 5476030

Browse files
feat: add basic env logging and update Py version to 3.11 (#6)
* feat: add basic env logging * fix: remove redundant Signed-off-by: Swarnim Arun <[email protected]> * Add py3.11 Signed-off-by: Deepak Raj H R <[email protected]> * Apply suggestions from code review Signed-off-by: Deepak Raj H R <[email protected]> * Fix order Signed-off-by: Deepak Raj H R <[email protected]> * Missing yes Signed-off-by: Deepak Raj H R <[email protected]> --------- Signed-off-by: Swarnim Arun <[email protected]> Signed-off-by: Deepak Raj H R <[email protected]> Co-authored-by: Deepak Raj H R <[email protected]>
1 parent 3c11031 commit 5476030

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010
serde = { version = "1.0.144", features = ["derive"] }
1111
# json support
1212
serde_json = "1.0.85"
13-
log = { version = "0.4.17" }
13+
log = { version = "0.4.17", features = ["std"]}
1414
atty = "0.2.14"
1515
walkdir = "2.3.2"
1616
quick-xml = { version = "0.28.0", features = ["serialize"] }

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ ENV DEBIAN_FRONTEND=noninteractive
77
# update the system and install any dependencies
88
RUN apt-get update \
99
&& apt-get upgrade -y libksba-dev \
10-
&& apt-get install -y git cmake build-essential byacc libpcre3 libpcre3-dev grep lsb-release wget software-properties-common gnupg libcurl4-openssl-dev unzip lcov --no-install-recommends # skipcq: DOK-DL3018
10+
&& apt-get install -y software-properties-common \
11+
&& add-apt-repository ppa:deadsnakes/ppa\
12+
&& apt-get install -y git cmake build-essential byacc libpcre3 libpcre3-dev grep lsb-release wget gnupg libcurl4-openssl-dev unzip lcov python3.11 --no-install-recommends # skipcq: DOK-DL3018
1113

1214
# Get LLVM
1315
ARG LLVM_VER=16

src/fmtlogger.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::OnceLock;
2+
13
use log::{Level, LevelFilter, Log, Metadata, Record};
24

35
const CLICOLOR_FORCE: &str = "CLICOLOR_FORCE";
@@ -65,11 +67,21 @@ impl Log for Logger {
6567
}
6668

6769
pub fn default() {
68-
const LOGGER: Logger = Logger {
69-
level: LevelFilter::Trace,
70-
};
71-
log::set_max_level(LOGGER.level);
72-
if let Err(err) = log::set_logger(&LOGGER) {
70+
static LOGGER: OnceLock<Logger> = OnceLock::new();
71+
let logger = LOGGER.get_or_init(|| Logger {
72+
level: std::env::var("RUST_LOG")
73+
.map(|x| match x.as_str() {
74+
"warn" => log::LevelFilter::Warn,
75+
"trace" => log::LevelFilter::Trace,
76+
"error" => log::LevelFilter::Error,
77+
"info" => log::LevelFilter::Info,
78+
"debug" => log::LevelFilter::Debug,
79+
_ => log::LevelFilter::Trace,
80+
})
81+
.unwrap_or(log::LevelFilter::Trace),
82+
});
83+
log::set_max_level(logger.level);
84+
if let Err(err) = log::set_boxed_logger(Box::new(logger)) {
7385
// used const to allow for static lifetime
7486
eprintln!("attaching logger failed! shouldn't be possible: {:?}", err);
7587
}

0 commit comments

Comments
 (0)