Skip to content

Commit

Permalink
cli: improve readability of application output
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyn committed Mar 7, 2025
1 parent f7cd9a2 commit dcf3a84
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ chrono = "0.4"
dbus = { version = "0.9", optional = true }
dbus-tokio = { version = "0.7.3", optional = true }
dbus-crossroads = { version = "0.5.0", optional = true }
fern = { version = "0.7.0", features = ["syslog-6"] }
fern = { version = "0.7.0", features = ["syslog-6", "colored"] }
futures = "0.3.15"
gethostname = "0.5.0"
hex = "0.4"
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ where
toml::Value::String(num) => {
return u8::from_str(&num)
.map(Some)
.inspect(|_| warn!("Configuration Warning: `initial_volume` should be a number rather than a string, this will become a hard error in the future"))
.inspect(|_| warn!("`initial_volume` should be a number rather than a string, this will become a hard error in the future"))
.map_err(de::Error::custom)
}
toml::Value::Float(f) => Unexpected::Float(f),
Expand Down Expand Up @@ -484,14 +484,14 @@ impl CliConfig {
if let Some(problem) = get_known_config_problem(&path) {
match problem {
KnownConfigProblem::MissingFeature(feature) => {
warn!("Warning: The config key '{path}' is ignored, because the feature '{feature}' is missing in this build");
warn!("The config key '{path}' is ignored, because the feature '{feature}' is missing in this build");
}
KnownConfigProblem::UsernamePassword => {
warn!("Warning: Authentication via Username and Password is no longer supported by Spotify, use ```spotifyd authenticate` instead");
warn!("The config key '{path}' is ignored, because authentication with username and password is no longer supported by Spotify. Please use `spotifyd authenticate` instead");
}
}
} else {
warn!("Warning: Unknown key '{path}' in config will be ignored");
warn!("Unknown key '{path}' in config will be ignored");
}
})?;

Expand Down
36 changes: 23 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use color_eyre::eyre::{self, Context};
use config::ExecutionMode;
#[cfg(unix)]
use daemonize::Daemonize;
use fern::colors::ColoredLevelConfig;
#[cfg(unix)]
use log::error;
use log::{info, trace, LevelFilter};
Expand Down Expand Up @@ -40,23 +41,32 @@ fn setup_logger(log_target: LogTarget, verbose: u8) -> eyre::Result<()> {
1 => LevelFilter::Debug,
2.. => LevelFilter::Trace,
};

let mut logger = fern::Dispatch::new().level(log_level);

logger = if verbose > 0 {
logger.format(|out, message, record| {
out.finish(format_args!(
"[{} {}] {}",
record.level(),
record.target(),
message
))
})
} else {
logger.level_for("symphonia_format_ogg::demuxer", LevelFilter::Warn)
};
if verbose == 0 {
logger = logger.level_for("symphonia_format_ogg::demuxer", LevelFilter::Warn);
}

let logger = match log_target {
LogTarget::Terminal => logger.chain(std::io::stdout()),
LogTarget::Terminal => {
let colors = ColoredLevelConfig::new();
logger
.format(move |out, message, record| {
let target = if verbose > 0 {
&format!(" {}", record.target())
} else {
""
};
out.finish(format_args!(
"[{}{}] {}",
colors.color(record.level()),
target,
message
))
})
.chain(std::io::stdout())
}
#[cfg(unix)]
LogTarget::Syslog => {
let log_format = syslog::Formatter3164 {
Expand Down

0 comments on commit dcf3a84

Please sign in to comment.