Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1552085

Browse files
committedJan 8, 2024
address pr review feedback from @xzfc
1 parent 8224c4c commit 1552085

File tree

4 files changed

+24
-140
lines changed

4 files changed

+24
-140
lines changed
 

‎Cargo.lock

+5-129
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ which = "4.4.0"
1111
[dependencies]
1212
blake3 = "1.3.3"
1313
bytelines = "2.4.0"
14-
env_logger = "0.10.1"
14+
env_logger = { version = "0.10.1", default-features = false }
1515
itertools = "0.10.5"
1616
log = "0.4.20"
1717
nix = "0.26.2"

‎src/main.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use std::process::{exit, Command, Stdio};
1919
use std::time::Instant;
2020
use tempfile::NamedTempFile;
2121
use ufcs::Pipe;
22-
use log::{debug, error, warn, info};
23-
use env_logger::{Builder, Env};
22+
use log::{error, warn, info};
23+
use env_logger::{Builder, Env, Target};
2424

2525
mod args;
2626
mod bash;
@@ -337,15 +337,13 @@ fn run_script(
337337

338338
let exec = if is_literal_bash_string(nix_shell_args.interpreter.as_bytes())
339339
{
340-
debug!("Interpreter is a literal string, executing directly");
341340
Command::new(nix_shell_args.interpreter)
342341
.arg(fname)
343342
.args(script_args)
344343
.env_clear()
345344
.envs(&env.env)
346345
.exec()
347346
} else {
348-
debug!("Interpreter is bash command, executing 'bash -c'");
349347
let mut exec_string = OsString::new();
350348
exec_string.push("exec ");
351349
exec_string.push(nix_shell_args.interpreter);
@@ -640,18 +638,28 @@ fn wrap(cmd: Vec<OsString>) {
640638
exit(1);
641639
}
642640

643-
fn init_logger() {
641+
fn init_logger(target: Target) {
644642
let env = Env::default()
645-
.filter("CNS_LOG_LEVEL")
643+
.filter_or("CNS_LOG_LEVEL", "trace")
646644
.write_style("CNS_LOG_STYLE");
647645

648-
Builder::from_env(env).init();
646+
Builder::from_env(env)
647+
.format_level(false)
648+
.target(target)
649+
.init();
649650
}
650651

651652
fn main() {
652-
init_logger();
653653
let argv: Vec<OsString> = std::env::args_os().collect();
654654

655+
// We need to print version into stdout, this is why the condition.
656+
// A naive assumption: the version could be only the first and a single CLI argument.
657+
init_logger(if argv.len() == 2 && argv[1] == "--version" {
658+
Target::Stdout
659+
} else {
660+
Target::Stderr
661+
});
662+
655663
if argv.len() >= 2 && argv[1] == "--wrap" {
656664
wrap(std::env::args_os().skip(2).collect());
657665
}

‎src/trace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ffi::{OsStr, OsString};
44
use std::fs::{read, read_dir, read_link, symlink_metadata};
55
use std::io::ErrorKind;
66
use std::os::unix::ffi::OsStrExt;
7-
use log::error;
7+
use log::info;
88

99
/// Output of trace-nix.so, sorted and deduplicated.
1010
pub struct Trace {
@@ -81,7 +81,7 @@ fn check_item_updated(k: &[u8], v: &[u8]) -> bool {
8181
};
8282

8383
if res.as_bytes() != v {
84-
error!(
84+
info!(
8585
"{:?}: expected {:?}, got {:?}",
8686
fname,
8787
OsStr::from_bytes(v),

0 commit comments

Comments
 (0)
Please sign in to comment.