From cf53bf24575678fce0c30a2f45450ca6aa923390 Mon Sep 17 00:00:00 2001 From: reuben olinsky Date: Mon, 13 May 2024 06:57:28 -0700 Subject: [PATCH] Move from log -> tracing; enable dynamic selection (#7) * Switch from log to tracing * Enable runtime tracing options * Fix workflow definition --- .github/workflows/ci.yaml | 1 + Cargo.lock | 133 ++++++++++++++++----- cli/Cargo.toml | 4 +- cli/src/main.rs | 80 ++++++++++--- interactive-shell/Cargo.toml | 2 +- interactive-shell/src/interactive_shell.rs | 4 +- parser/Cargo.toml | 2 +- parser/src/arithmetic.rs | 2 +- parser/src/parser.rs | 13 +- parser/src/word.rs | 4 +- shell/Cargo.toml | 2 +- shell/src/builtins/complete.rs | 4 +- shell/src/builtins/eval.rs | 2 +- shell/src/builtins/read.rs | 2 +- shell/src/completion.rs | 74 ++++++------ shell/src/interp.rs | 14 +-- shell/src/shell.rs | 12 +- shell/src/variables.rs | 2 +- 18 files changed, 242 insertions(+), 115 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 17c90581..41e243dc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,5 +1,6 @@ name: "CI" on: + pull_request: {} push: paths-ignore: - "docs/**" diff --git a/Cargo.lock b/Cargo.lock index 54e15b1e..032d0553 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,12 +250,10 @@ dependencies = [ "colored", "descape", "dir-cmp", - "env_logger 0.11.3", "expectrl", "glob", "indent", "junit-report", - "log", "pathdiff", "prettydiff", "regex", @@ -263,6 +261,8 @@ dependencies = [ "serde_yaml", "strip-ansi-escapes", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] @@ -272,10 +272,10 @@ dependencies = [ "anyhow", "brush-parser", "brush-shell", - "log", "rustyline", "thiserror", "tokio", + "tracing", ] [[package]] @@ -286,10 +286,10 @@ dependencies = [ "assert_matches", "criterion", "indenter", - "log", "peg", "pprof", "thiserror", + "tracing", "utf8-chars", ] @@ -312,7 +312,6 @@ dependencies = [ "indexmap", "itertools 0.12.1", "lazy_static", - "log", "nix 0.28.0", "os_pipe", "pprof", @@ -321,6 +320,7 @@ dependencies = [ "tokio", "tokio-command-fds", "tokio-macros", + "tracing", "uzers", "whoami", ] @@ -624,7 +624,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76924c3bfb58021d733dc17d96d9c461a768555bbd68c82702f08cef5fdbae2d" dependencies = [ "clap", - "env_logger 0.10.2", + "env_logger", "log", "regex", "serde", @@ -649,16 +649,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "env_filter" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" -dependencies = [ - "log", - "regex", -] - [[package]] name = "env_logger" version = "0.10.2" @@ -672,19 +662,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "env_logger" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -1258,6 +1235,16 @@ dependencies = [ "libc", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -1324,6 +1311,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "pad" version = "0.1.6" @@ -1777,6 +1770,15 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -1920,6 +1922,16 @@ dependencies = [ "syn 2.0.63", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "time" version = "0.3.36" @@ -2000,6 +2012,63 @@ dependencies = [ "syn 2.0.63", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -2055,6 +2124,12 @@ dependencies = [ "log", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index f86e177e..fa042a01 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -24,9 +24,9 @@ brush-interactive-shell = { path = "../interactive-shell" } brush-parser = { path = "../parser" } brush-shell = { path = "../shell" } clap = { version = "4.5.4", features = ["derive"] } -env_logger = "0.11.3" -log = "0.4.21" tokio = { version = "1.37.0", features = ["rt", "rt-multi-thread"] } +tracing = "0.1.40" +tracing-subscriber = "0.3.18" [dev-dependencies] anyhow = "1.0.82" diff --git a/cli/src/main.rs b/cli/src/main.rs index dc80f8ed..e3dbd5f4 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,7 +1,7 @@ -use std::{io::IsTerminal, io::Write, path::Path}; +use std::{collections::HashSet, io::IsTerminal, path::Path}; use clap::Parser; -use log::error; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Layer}; #[derive(Parser)] #[clap(version, about, disable_help_flag = true, disable_version_flag = true)] @@ -62,6 +62,9 @@ struct CommandLineArgs { #[clap(long = "disable-bracketed-paste", help = "Disable bracketed paste.")] disable_bracketed_paste: bool, + #[clap(long = "log-enable")] + enabled_log_events: Vec, + #[clap(help = "Path to script to execute")] script_path: Option, @@ -69,6 +72,20 @@ struct CommandLineArgs { script_args: Vec, } +#[derive(Clone, Debug, Eq, Hash, PartialEq, clap::ValueEnum)] +enum TraceEvent { + #[clap(name = "arithmetic")] + Arithmetic, + #[clap(name = "complete")] + Complete, + #[clap(name = "expand")] + Expand, + #[clap(name = "parse")] + Parse, + #[clap(name = "tokenize")] + Tokenize, +} + impl CommandLineArgs { pub fn is_interactive(&self) -> bool { if self.interactive { @@ -88,25 +105,59 @@ impl CommandLineArgs { } fn main() { - // Initialize logging. Default log level to INFO if not explicitly specified by the env. - // Keep verbosity on rustyline no more than WARNING, since it otherwise gets quite noisy. - env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")) - .filter_module("rustyline", log::LevelFilter::Warn) - .format(|buf, record| writeln!(buf, "{}", record.args())) - .init(); - + // + // Parse args. + // let args: Vec<_> = std::env::args().collect(); + let parsed_args = CommandLineArgs::parse_from(&args); + + // + // Initializing tracing. + // + let mut filter = tracing_subscriber::filter::Targets::new() + .with_default(tracing_subscriber::filter::LevelFilter::INFO); + + let enabled_trace_events: HashSet = + parsed_args.enabled_log_events.iter().cloned().collect(); + for event in enabled_trace_events { + let targets = match event { + TraceEvent::Arithmetic => vec!["parser::arithmetic"], + TraceEvent::Complete => vec!["shell::completion", "shell::builtins::complete"], + TraceEvent::Expand => vec![], + TraceEvent::Parse => vec!["parse"], + TraceEvent::Tokenize => vec!["tokenize"], + }; + + filter = filter.with_targets( + targets + .into_iter() + .map(|target| (target, tracing::Level::DEBUG)), + ); + } + + let stderr_log_layer = tracing_subscriber::fmt::layer() + .with_writer(std::io::stderr) + .without_time() + .with_filter(filter); + tracing_subscriber::registry() + .with(stderr_log_layer) + .try_init() + .expect("Failed to initialize tracing."); + + // + // Run. + // let result = tokio::runtime::Builder::new_multi_thread() .enable_all() .build() .unwrap() - .block_on(run(args)); + .block_on(run(args, parsed_args)); let exit_code = match result { Ok(code) => code, Err(e) => { - error!("error: {:#}", e); + tracing::error!("error: {:#}", e); 1 } }; @@ -115,9 +166,10 @@ fn main() { std::process::exit(exit_code as i32); } -async fn run(cli_args: Vec) -> Result { - let args = CommandLineArgs::parse_from(&cli_args); - +async fn run( + cli_args: Vec, + args: CommandLineArgs, +) -> Result { let argv0 = if args.sh_mode { // Simulate having been run as "sh". Some(String::from("sh")) diff --git a/interactive-shell/Cargo.toml b/interactive-shell/Cargo.toml index 857cd140..36ef069d 100644 --- a/interactive-shell/Cargo.toml +++ b/interactive-shell/Cargo.toml @@ -16,10 +16,10 @@ workspace = true anyhow = "1.0.83" brush-parser = { path = "../parser" } brush-shell = { path = "../shell" } -log = "0.4.21" rustyline = { git = "https://github.com/reubeno/rustyline", rev = "023a08093e9b8ff81f9d8e096e00a23e6e83167a", features = ["derive"] } thiserror = "1.0.58" tokio = { version = "1.37.0", features = [ "macros", "signal", ] } +tracing = "0.1.40" diff --git a/interactive-shell/src/interactive_shell.rs b/interactive-shell/src/interactive_shell.rs index ed849a8b..7dcecdc4 100644 --- a/interactive-shell/src/interactive_shell.rs +++ b/interactive-shell/src/interactive_shell.rs @@ -92,12 +92,12 @@ impl InteractiveShell { } if return_from_function_or_script { - log::error!("return from non-function/script"); + tracing::error!("return from non-function/script"); } } InteractiveExecutionResult::Failed(e) => { // Report the error, but continue to execute. - log::error!("error: {:#}", e); + tracing::error!("error: {:#}", e); } InteractiveExecutionResult::Eof => { break; diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 66715c4b..3eec48d8 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -18,9 +18,9 @@ if_same_then_else = "allow" [dependencies] indenter = "0.3.3" -log = "0.4.21" peg = "0.8.3" thiserror = "1.0.58" +tracing = "0.1.40" utf8-chars = "3.0.2" [dev-dependencies] diff --git a/parser/src/arithmetic.rs b/parser/src/arithmetic.rs index 4b422706..2f430571 100644 --- a/parser/src/arithmetic.rs +++ b/parser/src/arithmetic.rs @@ -4,7 +4,7 @@ use crate::error; pub fn parse_arithmetic_expression( input: &str, ) -> Result { - log::debug!("parsing arithmetic expression: '{input}'"); + tracing::debug!("parsing arithmetic expression: '{input}'"); // Special-case the empty string. diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 57696227..ac99f949 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -1,5 +1,3 @@ -use log::debug; - use crate::ast::{self, SeparatorOperator}; use crate::error; use crate::tokenizer::{Token, TokenEndReason, Tokenizer, TokenizerOptions, Tokens}; @@ -72,10 +70,7 @@ impl Parser { }; if let Some(token) = result.token { - if log::log_enabled!(log::Level::Debug) { - debug!("TOKEN {}: {:?}", tokens.len(), token); - } - + tracing::debug!(target: "tokenize", "TOKEN {}: {:?}", tokens.len(), token); tokens.push(token); } @@ -102,7 +97,7 @@ pub fn parse_tokens( let result = match parse_result { Ok(program) => Ok(program), Err(parse_error) => { - debug!("Parse error: {:?}", parse_error); + tracing::debug!("Parse error: {:?}", parse_error); Err(error::convert_peg_parse_error( parse_error, tokens.as_slice(), @@ -110,9 +105,9 @@ pub fn parse_tokens( } }; - if log::log_enabled!(log::Level::Debug) { + if tracing::enabled!(tracing::Level::DEBUG) { if let Ok(program) = &result { - debug!("PROG: {:?}", program); + tracing::debug!(target: "parse", "PROG: {:?}", program); } } diff --git a/parser/src/word.rs b/parser/src/word.rs index f02a680f..f1a2dc72 100644 --- a/parser/src/word.rs +++ b/parser/src/word.rs @@ -168,12 +168,12 @@ pub fn parse_word_for_expansion( word: &str, options: &ParserOptions, ) -> Result, error::WordParseError> { - log::debug!("Parsing word '{}'", word); + tracing::debug!("Parsing word '{}'", word); let pieces = expansion_parser::unexpanded_word(word, options) .map_err(|err| error::WordParseError::Word(word.to_owned(), err))?; - log::debug!("Parsed word '{}' => {{{:?}}}", word, pieces); + tracing::debug!("Parsed word '{}' => {{{:?}}}", word, pieces); Ok(pieces) } diff --git a/shell/Cargo.toml b/shell/Cargo.toml index d08d5e3b..d176559c 100644 --- a/shell/Cargo.toml +++ b/shell/Cargo.toml @@ -25,7 +25,6 @@ hostname = "0.4.0" indexmap = "2.2.6" itertools = "0.12.1" lazy_static = "1.4.0" -log = "0.4.21" os_pipe = "1.1.5" rand = "0.8.5" thiserror = "1.0.58" @@ -38,6 +37,7 @@ tokio = { version = "1.37.0", features = [ "signal", ] } tokio-macros = "2.2.0" +tracing = "0.1.40" [target.'cfg(windows)'.dependencies] homedir = "0.2.1" diff --git a/shell/src/builtins/complete.rs b/shell/src/builtins/complete.rs index 6750a607..77f357ea 100644 --- a/shell/src/builtins/complete.rs +++ b/shell/src/builtins/complete.rs @@ -503,9 +503,9 @@ impl BuiltinCommand for CompOptCommand { // TODO: implement options for (option, value) in options { if value { - log::debug!("compopt: enabling {option:?}"); + tracing::debug!("compopt: enabling {option:?}"); } else { - log::debug!("compopt: disabling {option:?}"); + tracing::debug!("compopt: disabling {option:?}"); } } diff --git a/shell/src/builtins/eval.rs b/shell/src/builtins/eval.rs index d2dac26a..68beb44d 100644 --- a/shell/src/builtins/eval.rs +++ b/shell/src/builtins/eval.rs @@ -19,7 +19,7 @@ impl BuiltinCommand for EvalCommand { if !self.args.is_empty() { let args_concatenated = self.args.join(" "); - log::debug!("Applying eval to: {:?}", args_concatenated); + tracing::debug!("Applying eval to: {:?}", args_concatenated); let exec_result = context .shell diff --git a/shell/src/builtins/read.rs b/shell/src/builtins/read.rs index 372a9f91..d99cec9d 100644 --- a/shell/src/builtins/read.rs +++ b/shell/src/builtins/read.rs @@ -69,7 +69,7 @@ impl BuiltinCommand for ReadCommand { return error::unimp("read -p"); } if self.raw_mode { - log::debug!("read -r is not implemented"); + tracing::debug!("read -r is not implemented"); } if self.silent { return error::unimp("read -s"); diff --git a/shell/src/completion.rs b/shell/src/completion.rs index cd7f36a7..a8d0668c 100644 --- a/shell/src/completion.rs +++ b/shell/src/completion.rs @@ -154,52 +154,56 @@ impl CompletionSpec { // Apply options if self.bash_default { - log::debug!("UNIMPLEMENTED: complete -o bashdefault"); + tracing::debug!("UNIMPLEMENTED: complete -o bashdefault"); } if self.default { - log::debug!("UNIMPLEMENTED: complete -o default"); + tracing::debug!("UNIMPLEMENTED: complete -o default"); } if self.dir_names { - log::debug!("UNIMPLEMENTED: complete -o dirnames"); + tracing::debug!("UNIMPLEMENTED: complete -o dirnames"); } if self.file_names { - log::debug!("UNIMPLEMENTED: complete -o filenames"); + tracing::debug!("UNIMPLEMENTED: complete -o filenames"); } if self.no_quote { - log::debug!("UNIMPLEMENTED: complete -o noquote"); + tracing::debug!("UNIMPLEMENTED: complete -o noquote"); } if self.no_space { - log::debug!("UNIMPLEMENTED: complete -o nospace"); + tracing::debug!("UNIMPLEMENTED: complete -o nospace"); } if self.plus_dirs { - log::debug!("UNIMPLEMENTED: complete -o plusdirs"); + tracing::debug!("UNIMPLEMENTED: complete -o plusdirs"); } for action in &self.actions { match action { - CompleteAction::Alias => log::debug!("UNIMPLEMENTED: complete -A alias"), - CompleteAction::ArrayVar => log::debug!("UNIMPLEMENTED: complete -A arrayvar"), - CompleteAction::Binding => log::debug!("UNIMPLEMENTED: complete -A binding"), - CompleteAction::Builtin => log::debug!("UNIMPLEMENTED: complete -A builtin"), - CompleteAction::Command => log::debug!("UNIMPLEMENTED: complete -A command"), - CompleteAction::Directory => log::debug!("UNIMPLEMENTED: complete -A directory"), - CompleteAction::Disabled => log::debug!("UNIMPLEMENTED: complete -A disabled"), - CompleteAction::Enabled => log::debug!("UNIMPLEMENTED: complete -A enabled"), - CompleteAction::Export => log::debug!("UNIMPLEMENTED: complete -A export"), - CompleteAction::File => log::debug!("UNIMPLEMENTED: complete -A file"), - CompleteAction::Function => log::debug!("UNIMPLEMENTED: complete -A function"), - CompleteAction::Group => log::debug!("UNIMPLEMENTED: complete -A group"), - CompleteAction::HelpTopic => log::debug!("UNIMPLEMENTED: complete -A helptopic"), - CompleteAction::HostName => log::debug!("UNIMPLEMENTED: complete -A hostname"), - CompleteAction::Job => log::debug!("UNIMPLEMENTED: complete -A job"), - CompleteAction::Keyword => log::debug!("UNIMPLEMENTED: complete -A keyword"), - CompleteAction::Running => log::debug!("UNIMPLEMENTED: complete -A running"), - CompleteAction::Service => log::debug!("UNIMPLEMENTED: complete -A service"), - CompleteAction::SetOpt => log::debug!("UNIMPLEMENTED: complete -A setopt"), - CompleteAction::ShOpt => log::debug!("UNIMPLEMENTED: complete -A shopt"), - CompleteAction::Signal => log::debug!("UNIMPLEMENTED: complete -A signal"), - CompleteAction::Stopped => log::debug!("UNIMPLEMENTED: complete -A stopped"), - CompleteAction::User => log::debug!("UNIMPLEMENTED: complete -A user"), + CompleteAction::Alias => tracing::debug!("UNIMPLEMENTED: complete -A alias"), + CompleteAction::ArrayVar => tracing::debug!("UNIMPLEMENTED: complete -A arrayvar"), + CompleteAction::Binding => tracing::debug!("UNIMPLEMENTED: complete -A binding"), + CompleteAction::Builtin => tracing::debug!("UNIMPLEMENTED: complete -A builtin"), + CompleteAction::Command => tracing::debug!("UNIMPLEMENTED: complete -A command"), + CompleteAction::Directory => { + tracing::debug!("UNIMPLEMENTED: complete -A directory"); + } + CompleteAction::Disabled => tracing::debug!("UNIMPLEMENTED: complete -A disabled"), + CompleteAction::Enabled => tracing::debug!("UNIMPLEMENTED: complete -A enabled"), + CompleteAction::Export => tracing::debug!("UNIMPLEMENTED: complete -A export"), + CompleteAction::File => tracing::debug!("UNIMPLEMENTED: complete -A file"), + CompleteAction::Function => tracing::debug!("UNIMPLEMENTED: complete -A function"), + CompleteAction::Group => tracing::debug!("UNIMPLEMENTED: complete -A group"), + CompleteAction::HelpTopic => { + tracing::debug!("UNIMPLEMENTED: complete -A helptopic"); + } + CompleteAction::HostName => tracing::debug!("UNIMPLEMENTED: complete -A hostname"), + CompleteAction::Job => tracing::debug!("UNIMPLEMENTED: complete -A job"), + CompleteAction::Keyword => tracing::debug!("UNIMPLEMENTED: complete -A keyword"), + CompleteAction::Running => tracing::debug!("UNIMPLEMENTED: complete -A running"), + CompleteAction::Service => tracing::debug!("UNIMPLEMENTED: complete -A service"), + CompleteAction::SetOpt => tracing::debug!("UNIMPLEMENTED: complete -A setopt"), + CompleteAction::ShOpt => tracing::debug!("UNIMPLEMENTED: complete -A shopt"), + CompleteAction::Signal => tracing::debug!("UNIMPLEMENTED: complete -A signal"), + CompleteAction::Stopped => tracing::debug!("UNIMPLEMENTED: complete -A stopped"), + CompleteAction::User => tracing::debug!("UNIMPLEMENTED: complete -A user"), CompleteAction::Variable => { shell.env.iter().for_each(|(key, _value)| { candidates.push(key.to_string()); @@ -209,10 +213,10 @@ impl CompletionSpec { } if let Some(glob_pattern) = &self.glob_pattern { - log::debug!("UNIMPLEMENTED: complete -G({glob_pattern})"); + tracing::debug!("UNIMPLEMENTED: complete -G({glob_pattern})"); } if let Some(word_list) = &self.word_list { - log::debug!("UNIMPLEMENTED: complete -W({word_list})"); + tracing::debug!("UNIMPLEMENTED: complete -W({word_list})"); } if let Some(function_name) = &self.function_name { let call_result = self @@ -226,7 +230,7 @@ impl CompletionSpec { } } if let Some(command) = &self.command { - log::debug!("UNIMPLEMENTED: complete -C({command})"); + tracing::debug!("UNIMPLEMENTED: complete -C({command})"); } // Make sure the token we have (if non-empty) is a prefix. @@ -236,7 +240,7 @@ impl CompletionSpec { // Apply filter pattern, if present. if let Some(filter_pattern) = &self.filter_pattern { - log::debug!("UNIMPLEMENTED: complete -X (filter pattern): {filter_pattern}"); + tracing::debug!("UNIMPLEMENTED: complete -X (filter pattern): {filter_pattern}"); } // Add prefix and/or suffix, if present. @@ -406,7 +410,7 @@ impl CompletionConfig { let mut restart_count = 0; while matches!(result, CompletionResult::RestartCompletionProcess) { if restart_count > MAX_RESTARTS { - log::error!("possible infinite loop detected in completion process"); + tracing::error!("possible infinite loop detected in completion process"); break; } diff --git a/shell/src/interp.rs b/shell/src/interp.rs index 0425c07d..63617af7 100644 --- a/shell/src/interp.rs +++ b/shell/src/interp.rs @@ -43,7 +43,7 @@ impl From for ExecutionResult { return Self::new((signal & 0xFF) as u8 + 128); } - log::error!("unhandled process exit"); + tracing::error!("unhandled process exit"); Self::new(127) } } @@ -1223,7 +1223,7 @@ async fn execute_external_command( } } - log::debug!( + tracing::debug!( "Spawning: {} {}", cmd.as_std().get_program().to_string_lossy().to_string(), cmd.as_std() @@ -1245,19 +1245,19 @@ async fn execute_external_command( } Err(e) if e.kind() == std::io::ErrorKind::NotFound => { if context.shell.options.sh_mode { - log::error!( + tracing::error!( "{}: {}: {}: not found", context.shell.shell_name.as_ref().unwrap_or(&String::new()), context.shell.get_current_input_line_number(), context.command_name ); } else { - log::error!("{}: not found", context.command_name); + tracing::error!("{}: not found", context.command_name); } Ok(SpawnResult::ImmediateExit(127)) } Err(e) => { - log::error!("error: {}", e); + tracing::error!("error: {}", e); Ok(SpawnResult::ImmediateExit(126)) } } @@ -1284,7 +1284,7 @@ async fn execute_builtin_command( } }, Err(e) => { - log::error!("error: {}", e); + tracing::error!("error: {}", e); 1 } }; @@ -1472,7 +1472,7 @@ async fn setup_redirect<'a>( if let Some(f) = open_files.files.get(fd) { target_file = f.try_dup()?; } else { - log::error!("{}: Bad file descriptor", fd); + tracing::error!("{}: Bad file descriptor", fd); return Ok(None); } } diff --git a/shell/src/shell.rs b/shell/src/shell.rs index 49b05ed3..f434a431 100644 --- a/shell/src/shell.rs +++ b/shell/src/shell.rs @@ -306,7 +306,7 @@ impl Shell { self.source(path, &args, params).await?; Ok(true) } else { - log::debug!("skipping non-existent file: {}", path.display()); + tracing::debug!("skipping non-existent file: {}", path.display()); Ok(false) } } @@ -317,7 +317,7 @@ impl Shell { args: &[S], params: &ExecutionParameters, ) -> Result { - log::debug!("sourcing: {}", path.display()); + tracing::debug!("sourcing: {}", path.display()); let opened_file = std::fs::File::open(path) .map_err(|e| error::Error::FailedSourcingFile(path.to_owned(), e))?; @@ -497,7 +497,7 @@ impl Shell { Ok(prog) => match self.run_program(prog, params).await { Ok(result) => result, Err(e) => { - log::error!("error: {:#}", e); + tracing::error!("error: {:#}", e); self.last_exit_status = 1; ExecutionResult::new(1) } @@ -505,7 +505,7 @@ impl Shell { Err(parser::ParseError::ParsingNearToken(token_near_error)) => { let error_loc = &token_near_error.location().start; - log::error!( + tracing::error!( "{}syntax error near token `{}' (line {} col {})", error_prefix, token_near_error.to_str(), @@ -516,7 +516,7 @@ impl Shell { ExecutionResult::new(2) } Err(parser::ParseError::ParsingAtEndOfInput) => { - log::error!("{}syntax error at end of input", error_prefix); + tracing::error!("{}syntax error at end of input", error_prefix); self.last_exit_status = 2; ExecutionResult::new(2) @@ -532,7 +532,7 @@ impl Shell { )); } - log::error!("{}", error_message); + tracing::error!("{}", error_message); self.last_exit_status = 2; ExecutionResult::new(2) diff --git a/shell/src/variables.rs b/shell/src/variables.rs index 756df3ba..ad4884dd 100644 --- a/shell/src/variables.rs +++ b/shell/src/variables.rs @@ -348,7 +348,7 @@ impl ShellVariable { Ok(()) } _ => { - log::error!("assigning to index {array_index} of {:?}", self.value); + tracing::error!("assigning to index {array_index} of {:?}", self.value); error::unimp("assigning to index of non-array variable") } }