Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove tracing::info usage #578

Merged
merged 22 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
36767a6
chore: remove tracing::info in favour of pure stdout
dutterbutter Feb 4, 2025
debc56d
chore: linting
dutterbutter Feb 4, 2025
0d3b49f
chore: fix formatting
dutterbutter Feb 4, 2025
32abbd8
feat: move to use shell io
dutterbutter Feb 4, 2025
83e902d
feat: introduce shell io abstraction for logging
dutterbutter Feb 4, 2025
270831f
Merge branch 'main' into db/remove-tracing-info
dutterbutter Feb 4, 2025
8903105
chore: remove clippy unused println
dutterbutter Feb 4, 2025
df52cfc
Merge branch 'db/remove-tracing-info' of github.com:matter-labs/anvil…
dutterbutter Feb 4, 2025
89e04dd
chore: linting
dutterbutter Feb 4, 2025
edb2789
feat: make use of anstream and anystyle, remove use of atty
dutterbutter Feb 6, 2025
82af8fe
chore: linting
dutterbutter Feb 6, 2025
a1701ff
Merge branch 'main' into db/remove-tracing-info
dutterbutter Feb 6, 2025
5e2e87d
feat: turn tracing off by default, update messages
dutterbutter Feb 6, 2025
fcba826
Merge branch 'db/remove-tracing-info' of github.com:matter-labs/anvil…
dutterbutter Feb 6, 2025
649e492
chore: resolve conflicts
dutterbutter Feb 6, 2025
b6c9d62
Merge branch 'main' into db/remove-tracing-info
dutterbutter Feb 7, 2025
9a8de7f
chore: make requested changes
dutterbutter Feb 10, 2025
85d5c9e
chore: update pool_rs
dutterbutter Feb 10, 2025
5508301
chore: linting, fix formatting. Remove uneeded colorize
dutterbutter Feb 10, 2025
4908676
chore: make requested changes
dutterbutter Feb 11, 2025
5801503
chore: linting
dutterbutter Feb 11, 2025
ffba45a
chore: resolve conflicts
dutterbutter Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ categories.workspace = true

[dependencies]
anstream.workspace = true
anstyle.workspace = true
anstyle.workspace = true
67 changes: 35 additions & 32 deletions crates/common/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use anstream::{AutoStream, ColorChoice as AnstreamColorChoice};
use anstyle::{AnsiColor, Effects, Reset, Style};
use std::fmt::Arguments;
use std::io::{self, IsTerminal, Write};
use std::sync::{Mutex, OnceLock};

Expand Down Expand Up @@ -72,63 +73,71 @@ impl Shell {
}

/// Print a string to stdout.
pub fn print_out(&mut self, msg: &str) -> io::Result<()> {
pub fn print_out(&mut self, args: Arguments) -> io::Result<()> {
if self.output_mode == OutputMode::Quiet {
return Ok(());
}
write!(self.stdout, "{}", msg)?;

self.stdout.write_fmt(args)?;
self.stdout.flush()
}

/// Print a line (with a newline) to stdout.
pub fn println_out(&mut self, msg: &str) -> io::Result<()> {
pub fn println_out(&mut self, args: Arguments) -> io::Result<()> {
if self.output_mode == OutputMode::Quiet {
return Ok(());
}
writeln!(self.stdout, "{}", msg)?;

self.stdout.write_fmt(args)?;
writeln!(self.stdout)?;
self.stdout.flush()
}

/// Print a string to stderr.
pub fn print_err(&mut self, msg: &str) -> io::Result<()> {
pub fn print_err(&mut self, args: Arguments) -> io::Result<()> {
if self.output_mode == OutputMode::Quiet {
return Ok(());
}
write!(self.stderr, "{}", msg)?;
self.stderr.write_fmt(args)?;
self.stderr.flush()
}

/// Print a line (with a newline) to stderr.
pub fn println_err(&mut self, msg: &str) -> io::Result<()> {
pub fn println_err(&mut self, args: Arguments) -> io::Result<()> {
if self.output_mode == OutputMode::Quiet {
return Ok(());
}
writeln!(self.stderr, "{}", msg)?;
self.stderr.write_fmt(args)?;
writeln!(self.stderr)?;
self.stderr.flush()
}

/// Print a warning message.
///
/// If colors are enabled, the “Warning:” prefix is printed in yellow.
pub fn warn(&mut self, msg: &str) -> io::Result<()> {
let prefix = if self.should_color() {
format!("{}Warning:{} ", WARN, Reset)
pub fn warn(&mut self, args: Arguments) -> io::Result<()> {
if self.should_color() {
write!(self.stderr, "{}Warning:{} ", WARN, Reset)?;
} else {
"Warning: ".to_string()
};
self.println_err(&format!("{}{}", prefix, msg))
write!(self.stderr, "Warning: ")?;
}
self.stderr.write_fmt(args)?;
writeln!(self.stderr)?;
self.stderr.flush()
}

/// Print an error message.
///
/// If colors are enabled, the “Error:” prefix is printed in red.
pub fn error(&mut self, msg: &str) -> io::Result<()> {
let prefix = if self.should_color() {
format!("{}Error:{} ", ERROR, Reset)
pub fn error(&mut self, args: Arguments) -> io::Result<()> {
if self.should_color() {
write!(self.stderr, "{}Error:{} ", ERROR, Reset)?;
} else {
"Error: ".to_string()
};
self.println_err(&format!("{}{}", prefix, msg))
write!(self.stderr, "Error: ")?;
}
self.stderr.write_fmt(args)?;
writeln!(self.stderr)?;
self.stderr.flush()
}

fn should_color(&self) -> bool {
Expand Down Expand Up @@ -179,8 +188,7 @@ pub fn set_shell(shell: Shell) {
#[macro_export]
macro_rules! sh_print {
($($arg:tt)*) => {{
let msg = format!($($arg)*);
$crate::shell::get_shell().print_out(&msg)
$crate::shell::get_shell().print_out(format_args!($($arg)*))
.unwrap_or_else(|e| eprintln!("Error writing output: {}", e));
}};
}
Expand All @@ -189,8 +197,7 @@ macro_rules! sh_print {
#[macro_export]
macro_rules! sh_println {
($($arg:tt)*) => {{
let msg = format!($($arg)*);
$crate::shell::get_shell().println_out(&msg)
$crate::shell::get_shell().println_out(format_args!($($arg)*))
.unwrap_or_else(|e| eprintln!("Error writing output: {}", e));
}};
}
Expand All @@ -199,8 +206,7 @@ macro_rules! sh_println {
#[macro_export]
macro_rules! sh_eprint {
($($arg:tt)*) => {{
let msg = format!($($arg)*);
$crate::shell::get_shell().print_err(&msg)
$crate::shell::get_shell().print_err(format_args!($($arg)*))
.unwrap_or_else(|e| eprintln!("Error writing stderr: {}", e));
}};
}
Expand All @@ -209,8 +215,7 @@ macro_rules! sh_eprint {
#[macro_export]
macro_rules! sh_eprintln {
($($arg:tt)*) => {{
let msg = format!($($arg)*);
$crate::shell::get_shell().println_err(&msg)
$crate::shell::get_shell().println_err(format_args!($($arg)*))
.unwrap_or_else(|e| eprintln!("Error writing stderr: {}", e));
}};
}
Expand All @@ -224,8 +229,7 @@ macro_rules! sh_eprintln {
#[macro_export]
macro_rules! sh_warn {
($($arg:tt)*) => {{
let msg = format!($($arg)*);
$crate::shell::get_shell().warn(&msg)
$crate::shell::get_shell().warn(format_args!($($arg)*))
.unwrap_or_else(|e| eprintln!("Error writing warning: {}", e));
}};
}
Expand All @@ -239,8 +243,7 @@ macro_rules! sh_warn {
#[macro_export]
macro_rules! sh_err {
($($arg:tt)*) => {{
let msg = format!($($arg)*);
$crate::shell::get_shell().error(&msg)
$crate::shell::get_shell().error(format_args!($($arg)*))
.unwrap_or_else(|e| eprintln!("Error writing error: {}", e));
}};
}
Expand Down
Loading