replaces all daemon prints with logs and enables logging by default (#168)

This commit is contained in:
legendofmiracles 2021-05-14 23:23:16 +02:00 committed by GitHub
parent e7a09dc571
commit 28c57afcd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 21 deletions

View file

@ -82,7 +82,7 @@ impl RawEwwConfig {
pub fn merge_includes(mut eww_config: RawEwwConfig, includes: Vec<RawEwwConfig>) -> Result<RawEwwConfig> { pub fn merge_includes(mut eww_config: RawEwwConfig, includes: Vec<RawEwwConfig>) -> Result<RawEwwConfig> {
let config_path = eww_config.filepath.clone(); let config_path = eww_config.filepath.clone();
let log_conflict = |what: &str, conflict: &str, included_path: &std::path::PathBuf| { let log_conflict = |what: &str, conflict: &str, included_path: &std::path::PathBuf| {
eprintln!( log::error!(
"{} '{}' defined twice (defined in {} and in {})", "{} '{}' defined twice (defined in {} and in {})",
what, what,
conflict, conflict,
@ -200,7 +200,7 @@ fn parse_variables_block(xml: XmlElement) -> Result<(HashMap<VarName, PrimVal>,
// Extends the variables with the predefined variables // Extends the variables with the predefined variables
let inbuilt = crate::config::inbuilt::get_inbuilt_vars(); let inbuilt = crate::config::inbuilt::get_inbuilt_vars();
for i in util::extend_safe(&mut script_vars, inbuilt) { for i in util::extend_safe(&mut script_vars, inbuilt) {
eprintln!( log::error!(
"script-var '{}' defined twice (defined in your config and in the eww included variables)\nHint: don't define any \ "script-var '{}' defined twice (defined in your config and in the eww included variables)\nHint: don't define any \
varible like any of these: https://elkowar.github.io/eww/main/magic-variables-documenation/", varible like any of these: https://elkowar.github.io/eww/main/magic-variables-documenation/",
i, i,

View file

@ -33,7 +33,7 @@ impl StateChangeHandler {
Ok(resolved_attrs) => { Ok(resolved_attrs) => {
crate::print_result_err!("while updating UI based after state change", &(self.func)(resolved_attrs)) crate::print_result_err!("while updating UI based after state change", &(self.func)(resolved_attrs))
} }
Err(err) => eprintln!("Error while resolving attributes: {:?}", err), Err(err) => log::error!("Error while resolving attributes: {:?}", err),
} }
} }
} }

View file

@ -35,9 +35,9 @@ pub mod widgets;
fn main() { fn main() {
let opts: opts::Opt = opts::Opt::from_env(); let opts: opts::Opt = opts::Opt::from_env();
let log_level_filter = if opts.log_debug { log::LevelFilter::Debug } else { log::LevelFilter::Off }; let log_level_filter = if opts.log_debug { log::LevelFilter::Debug } else { log::LevelFilter::Info };
pretty_env_logger::formatted_builder().filter(Some("eww"), log_level_filter).init(); pretty_env_logger::formatted_timed_builder().filter(Some("eww"), log_level_filter).init();
let result: Result<()> = try { let result: Result<()> = try {
let paths = opts let paths = opts
@ -89,7 +89,7 @@ fn main() {
}; };
if let Err(e) = result { if let Err(e) = result {
eprintln!("{:?}", e); log::error!("{:?}", e);
std::process::exit(1); std::process::exit(1);
} }
} }

View file

@ -15,9 +15,9 @@ pub fn initialize_server(paths: EwwPaths) -> Result<()> {
); );
simple_signal::set_handler(&[simple_signal::Signal::Int, simple_signal::Signal::Term], move |_| { simple_signal::set_handler(&[simple_signal::Signal::Int, simple_signal::Signal::Term], move |_| {
println!("Shutting down eww daemon..."); log::info!("Shutting down eww daemon...");
if let Err(e) = crate::application_lifecycle::send_exit() { if let Err(e) = crate::application_lifecycle::send_exit() {
eprintln!("Failed to send application shutdown event to workers: {:?}", e); log::error!("Failed to send application shutdown event to workers: {:?}", e);
std::process::exit(1); std::process::exit(1);
} }
}); });
@ -96,7 +96,7 @@ fn init_async_part(paths: EwwPaths, ui_send: UnboundedSender<app::DaemonCommand>
let result = tokio::try_join!(filewatch_join_handle, ipc_server_join_handle, forward_exit_to_app_handle); let result = tokio::try_join!(filewatch_join_handle, ipc_server_join_handle, forward_exit_to_app_handle);
if let Err(e) = result { if let Err(e) = result {
eprintln!("Eww exiting with error: {:?}", e); log::error!("Eww exiting with error: {:?}", e);
} }
}) })
}); });
@ -114,7 +114,7 @@ async fn run_filewatch<P: AsRef<Path>>(config_dir: P, evt_send: UnboundedSender<
log::warn!("Error forwarding file update event: {:?}", err); log::warn!("Error forwarding file update event: {:?}", err);
} }
} }
Err(e) => eprintln!("Encountered Error While Watching Files: {}", e), Err(e) => log::error!("Encountered Error While Watching Files: {}", e),
})?; })?;
watcher.watch(&config_dir, notify::RecursiveMode::Recursive)?; watcher.watch(&config_dir, notify::RecursiveMode::Recursive)?;
@ -130,9 +130,9 @@ async fn run_filewatch<P: AsRef<Path>>(config_dir: P, evt_send: UnboundedSender<
evt_send.send(app::DaemonCommand::ReloadConfigAndCss(daemon_resp_sender))?; evt_send.send(app::DaemonCommand::ReloadConfigAndCss(daemon_resp_sender))?;
tokio::spawn(async move { tokio::spawn(async move {
match daemon_resp_response.recv().await { match daemon_resp_response.recv().await {
Some(app::DaemonResponse::Success(_)) => println!("Reloaded config successfully"), Some(app::DaemonResponse::Success(_)) => log::info!("Reloaded config successfully"),
Some(app::DaemonResponse::Failure(e)) => eprintln!("Failed to reload config: {}", e), Some(app::DaemonResponse::Failure(e)) => log::error!("Failed to reload config: {}", e),
None => eprintln!("No response to reload configuration-reload request"), None => log::error!("No response to reload configuration-reload request"),
} }
}); });
} }

View file

@ -25,7 +25,7 @@ macro_rules! try_logging_errors {
($context:expr => $code:block) => {{ ($context:expr => $code:block) => {{
let result: Result<_> = try { $code }; let result: Result<_> = try { $code };
if let Err(err) = result { if let Err(err) = result {
eprintln!("[{}:{}] Error while {}: {:?}", ::std::file!(), ::std::line!(), $context, err); log::error!("[{}:{}] Error while {}: {:?}", ::std::file!(), ::std::line!(), $context, err);
} }
}}; }};
} }
@ -34,7 +34,7 @@ macro_rules! try_logging_errors {
macro_rules! print_result_err { macro_rules! print_result_err {
($context:expr, $result:expr $(,)?) => {{ ($context:expr, $result:expr $(,)?) => {{
if let Err(err) = $result { if let Err(err) = $result {
eprintln!("[{}:{}] Error {}: {:?}", ::std::file!(), ::std::line!(), $context, err); log::error!("[{}:{}] Error {}: {:?}", ::std::file!(), ::std::line!(), $context, err);
} }
}}; }};
} }

View file

@ -29,14 +29,14 @@ pub(self) fn run_command<T: 'static + std::fmt::Display + Send + Sync>(cmd: &str
Ok(mut child) => match child.wait_timeout(std::time::Duration::from_millis(200)) { Ok(mut child) => match child.wait_timeout(std::time::Duration::from_millis(200)) {
// child timed out // child timed out
Ok(None) => { Ok(None) => {
eprintln!("WARNING: command {} timed out", &cmd); log::error!("WARNING: command {} timed out", &cmd);
let _ = child.kill(); let _ = child.kill();
let _ = child.wait(); let _ = child.wait();
} }
Err(err) => eprintln!("Failed to execute command {}: {}", cmd, err), Err(err) => log::error!("Failed to execute command {}: {}", cmd, err),
Ok(Some(_)) => {} Ok(Some(_)) => {}
}, },
Err(err) => eprintln!("Failed to launch child process: {}", err), Err(err) => log::error!("Failed to launch child process: {}", err),
} }
}); });
} }
@ -106,8 +106,8 @@ fn build_builtin_gtk_widget(
resolve_widget_attrs(&mut bargs, &gtk_widget); resolve_widget_attrs(&mut bargs, &gtk_widget);
if !bargs.unhandled_attrs.is_empty() { if !bargs.unhandled_attrs.is_empty() {
eprintln!( log::error!(
"{}WARN: Unknown attribute used in {}: {}", "{}: Unknown attribute used in {}: {}",
widget.text_pos.map(|x| format!("{} | ", x)).unwrap_or_default(), widget.text_pos.map(|x| format!("{} | ", x)).unwrap_or_default(),
widget.name, widget.name,
bargs.unhandled_attrs.iter().map(|x| x.to_string()).join(", ") bargs.unhandled_attrs.iter().map(|x| x.to_string()).join(", ")
@ -167,7 +167,7 @@ macro_rules! log_errors {
($body:expr) => {{ ($body:expr) => {{
let result = try { $body }; let result = try { $body };
if let Err(e) = result { if let Err(e) = result {
eprintln!("WARN: {}", e); log::warn!("{}", e);
} }
}}; }};
} }