diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a0246416..8b4184fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Upon updating Pueue and restarting the daemon, the previous state will be wiped, - Change default log level from error to warning [#562](https://github.com/Nukesor/pueue/issues/562). - Bumped MSRV to 1.70. - **Breaking**: Redesigned task editing process [#553](https://github.com/Nukesor/pueue/issues/553). +- Print most of Pueue's info/log messages to `stderr`. Only keep useful stuff like json and task log output on `stdout`. ### Add diff --git a/pueue/src/bin/pueued.rs b/pueue/src/bin/pueued.rs index 949260754..2f066cfae 100644 --- a/pueue/src/bin/pueued.rs +++ b/pueue/src/bin/pueued.rs @@ -18,7 +18,7 @@ async fn main() -> Result<()> { // subcommand to install the service #[cfg(target_os = "windows")] if opt.service.is_some() { - println!("daemonize flag cannot be used with service subcommand"); + eprintln!("daemonize flag cannot be used with service subcommand"); return Ok(()); } @@ -120,7 +120,7 @@ fn fork_daemon(opt: &CliArguments) -> Result<()> { let current_exe = if let Ok(path) = std::env::current_exe() { path.to_string_lossy().clone().to_string() } else { - println!("Couldn't detect path of current binary. Falling back to 'pueue' in $PATH"); + eprintln!("Couldn't detect path of current binary. Falling back to 'pueue' in $PATH"); "pueued".to_string() }; diff --git a/pueue/src/client/client.rs b/pueue/src/client/client.rs index bef14f048..763e6eb05 100644 --- a/pueue/src/client/client.rs +++ b/pueue/src/client/client.rs @@ -352,7 +352,7 @@ impl Client { .map(|t| format!("task{t}")) .collect::>() .join(", "); - println!("You are trying to {action}: {task_ids}",); + eprintln!("You are trying to {action}: {task_ids}",); let mut input = String::new(); @@ -364,7 +364,7 @@ impl Client { match input.chars().next().unwrap() { 'N' | 'n' => { - println!("Aborted!"); + eprintln!("Aborted!"); std::process::exit(1); } '\n' | 'Y' | 'y' => { diff --git a/pueue/src/client/commands/restart.rs b/pueue/src/client/commands/restart.rs index 72e4c54d0..426d6c89e 100644 --- a/pueue/src/client/commands/restart.rs +++ b/pueue/src/client/commands/restart.rs @@ -165,7 +165,7 @@ pub async fn restart( println!("Restarted tasks: {:?}", filtered_tasks.matching_ids); } if !filtered_tasks.non_matching_ids.is_empty() { - println!( + eprintln!( "Couldn't restart tasks: {:?}", filtered_tasks.non_matching_ids ); diff --git a/pueue/src/client/commands/wait.rs b/pueue/src/client/commands/wait.rs index 5be63f575..7ca3c1739 100644 --- a/pueue/src/client/commands/wait.rs +++ b/pueue/src/client/commands/wait.rs @@ -58,7 +58,7 @@ pub async fn wait( let tasks = get_tasks(&state, &selection); if tasks.is_empty() { - println!("No tasks found for selection {selection:?}"); + eprintln!("No tasks found for selection {selection:?}"); return Ok(()); } diff --git a/pueue/src/client/display/follow.rs b/pueue/src/client/display/follow.rs index c0be99887..72c7d561e 100644 --- a/pueue/src/client/display/follow.rs +++ b/pueue/src/client/display/follow.rs @@ -29,7 +29,7 @@ pub async fn follow_local_task_logs( // Ensure that it exists and is started. loop { let Some(task) = get_task(stream, task_id).await? else { - println!("Pueue: The task to be followed doesn't exist."); + eprintln!("Pueue: The task to be followed doesn't exist."); std::process::exit(1); }; // Task started up, we can start to follow. @@ -42,7 +42,7 @@ pub async fn follow_local_task_logs( let mut handle = match get_log_file_handle(task_id, pueue_directory) { Ok(stdout) => stdout, Err(err) => { - println!("Failed to get log file handles: {err}"); + eprintln!("Failed to get log file handles: {err}"); return Ok(()); } }; @@ -58,7 +58,7 @@ pub async fn follow_local_task_logs( // The loop following this section will then only copy those last lines to stdout. if let Some(lines) = lines { if let Err(err) = seek_to_last_lines(&mut handle, lines) { - println!("Error seeking to last lines from log: {err}"); + eprintln!("Error seeking to last lines from log: {err}"); } } @@ -73,17 +73,17 @@ pub async fn follow_local_task_logs( loop { // Check whether the file still exists. Exit if it doesn't. if !path.exists() { - println!("Pueue: Log file has gone away. Has the task been removed?"); + eprintln!("Pueue: Log file has gone away. Has the task been removed?"); return Ok(()); } // Read the next chunk of text from the last position. if let Err(err) = io::copy(&mut handle, &mut stdout) { - println!("Pueue: Error while reading file: {err}"); + eprintln!("Pueue: Error while reading file: {err}"); return Ok(()); }; // Flush the stdout buffer to actually print the output. if let Err(err) = stdout.flush() { - println!("Pueue: Error while flushing stdout: {err}"); + eprintln!("Pueue: Error while flushing stdout: {err}"); return Ok(()); }; @@ -94,7 +94,7 @@ pub async fn follow_local_task_logs( // In case either is not, exit. if (last_check % task_check_interval) == 0 { let Some(task) = get_task(stream, task_id).await? else { - println!("Pueue: The followed task has been removed."); + eprintln!("Pueue: The followed task has been removed."); std::process::exit(1); }; // Task exited by itself. We can stop following. diff --git a/pueue/src/client/display/log/local.rs b/pueue/src/client/display/log/local.rs index 70cf07951..9946c1fb4 100644 --- a/pueue/src/client/display/log/local.rs +++ b/pueue/src/client/display/log/local.rs @@ -19,7 +19,7 @@ pub fn print_local_log( let mut file = match get_log_file_handle(task_id, &settings.shared.pueue_directory()) { Ok(file) => file, Err(err) => { - println!("Failed to get log file handle: {err}"); + eprintln!("Failed to get log file handle: {err}"); return; } }; @@ -47,7 +47,7 @@ fn print_local_file(stdout: &mut Stdout, file: &mut File, lines: &Option, match seek_to_last_lines(file, *lines) { Ok(complete) => output_complete = complete, Err(err) => { - println!("Failed reading local log file: {err}"); + eprintln!("Failed reading local log file: {err}"); return; } } @@ -61,11 +61,11 @@ fn print_local_file(stdout: &mut Stdout, file: &mut File, lines: &Option, } // Print a newline between the task information and the first output. - println!("\n{header}{line_info}"); + eprintln!("\n{header}{line_info}"); // Print everything if let Err(err) = io::copy(file, stdout) { - println!("Failed reading local log file: {err}"); + eprintln!("Failed reading local log file: {err}"); }; } } diff --git a/pueue/src/client/display/log/mod.rs b/pueue/src/client/display/log/mod.rs index 9b8accb76..de424b668 100644 --- a/pueue/src/client/display/log/mod.rs +++ b/pueue/src/client/display/log/mod.rs @@ -74,15 +74,15 @@ pub fn print_logs( if task_logs.is_empty() { match selection { TaskSelection::TaskIds(_) => { - println!("There are no finished tasks for your specified ids"); + eprintln!("There are no finished tasks for your specified ids"); return; } TaskSelection::Group(group) => { - println!("There are no finished tasks for group '{group}'"); + eprintln!("There are no finished tasks for group '{group}'"); return; } TaskSelection::All => { - println!("There are no finished tasks"); + eprintln!("There are no finished tasks"); return; } } @@ -174,7 +174,7 @@ fn print_task_info(task: &Task, style: &OutputStyle) { if style.enabled { table.enforce_styling(); } - println!("{table}"); + eprintln!("{table}"); // All other information is aligned and styled by using a separate table. let mut table = Table::new(); @@ -218,5 +218,5 @@ fn print_task_info(task: &Task, style: &OutputStyle) { first_column.set_cell_alignment(CellAlignment::Right); first_column.set_padding((0, 0)); - println!("{table}"); + eprintln!("{table}"); } diff --git a/pueue/src/client/display/log/remote.rs b/pueue/src/client/display/log/remote.rs index 32aa77328..12bd7adea 100644 --- a/pueue/src/client/display/log/remote.rs +++ b/pueue/src/client/display/log/remote.rs @@ -26,7 +26,7 @@ pub fn print_remote_log(task_log: &TaskLogMessage, style: &OutputStyle, lines: O println!("\n{header}{line_info}"); if let Err(err) = decompress_and_print_remote_log(bytes) { - println!("Error while parsing stdout: {err}"); + eprintln!("Error while parsing stdout: {err}"); } } } diff --git a/pueue/src/client/display/mod.rs b/pueue/src/client/display/mod.rs index 29f1d17bd..0c497af67 100644 --- a/pueue/src/client/display/mod.rs +++ b/pueue/src/client/display/mod.rs @@ -27,5 +27,5 @@ pub fn print_success(_style: &OutputStyle, message: &str) { /// Used to style any generic failure message from the daemon. pub fn print_error(style: &OutputStyle, message: &str) { let styled = style.style_text(message, Some(Color::Red), None); - println!("{styled}"); + eprintln!("{styled}"); } diff --git a/pueue/src/daemon/mod.rs b/pueue/src/daemon/mod.rs index c226f9ca2..e75c210f9 100644 --- a/pueue/src/daemon/mod.rs +++ b/pueue/src/daemon/mod.rs @@ -155,14 +155,14 @@ fn setup_signal_panic_handling(settings: &Settings, state: SharedState) -> Resul // Cleanup the pid file if let Err(error) = pid::cleanup_pid_file(&settings_clone.shared.pid_path()) { - println!("Failed to cleanup pid after panic."); - println!("{error}"); + eprintln!("Failed to cleanup pid after panic."); + eprintln!("{error}"); } // Remove the unix socket. if let Err(error) = socket_cleanup(&settings_clone.shared) { - println!("Failed to cleanup socket after panic."); - println!("{error}"); + eprintln!("Failed to cleanup socket after panic."); + eprintln!("{error}"); } std::process::exit(1); diff --git a/pueue/src/daemon/network/message_handler/log.rs b/pueue/src/daemon/network/message_handler/log.rs index 07e1f6a00..2bb68ae3a 100644 --- a/pueue/src/daemon/network/message_handler/log.rs +++ b/pueue/src/daemon/network/message_handler/log.rs @@ -140,7 +140,7 @@ pub async fn follow_log( // The loop following this section will then only copy those last lines to stdout. if let Some(lines) = message.lines { if let Err(err) = seek_to_last_lines(&mut handle, lines) { - println!("Error seeking to last lines from log: {err}"); + eprintln!("Error seeking to last lines from log: {err}"); } } diff --git a/pueue/src/daemon/service.rs b/pueue/src/daemon/service.rs index 0ae38d04d..eac8873f3 100644 --- a/pueue/src/daemon/service.rs +++ b/pueue/src/daemon/service.rs @@ -191,8 +191,8 @@ pub fn start_service() -> Result<()> { service.start::(&[])?; println!("Successfully started service"); } - ServiceState::StartPending => println!("Service is already starting"), - ServiceState::Running => println!("Service is already running"), + ServiceState::StartPending => eprintln!("Service is already starting"), + ServiceState::Running => eprintln!("Service is already running"), _ => (), } @@ -211,8 +211,8 @@ pub fn stop_service() -> Result<()> { let service = service_manager.open_service(SERVICE_NAME, service_access)?; match service.query_status()?.current_state { - ServiceState::Stopped => println!("Service is already stopped"), - ServiceState::StartPending => println!("Service cannot stop because it is starting (please wait until it fully started to stop it)"), + ServiceState::Stopped => eprintln!("Service is already stopped"), + ServiceState::StartPending => eprintln!("Service cannot stop because it is starting (please wait until it fully started to stop it)"), ServiceState::Running => { service.stop()?; println!("Successfully stopped service"); diff --git a/pueue/src/daemon/task_handler.rs b/pueue/src/daemon/task_handler.rs index 939186f68..c80e30371 100644 --- a/pueue/src/daemon/task_handler.rs +++ b/pueue/src/daemon/task_handler.rs @@ -80,14 +80,14 @@ fn handle_shutdown(settings: &Settings, state: &mut LockedState) { // Remove the unix socket. if let Err(error) = socket_cleanup(&settings.shared) { - println!("Failed to cleanup socket during shutdown."); - println!("{error}"); + eprintln!("Failed to cleanup socket during shutdown."); + eprintln!("{error}"); } // Cleanup the pid file if let Err(error) = cleanup_pid_file(&settings.shared.pid_path()) { - println!("Failed to cleanup pid during shutdown."); - println!("{error}"); + eprintln!("Failed to cleanup pid during shutdown."); + eprintln!("{error}"); } // Actually exit the program the way we're supposed to.