Skip to content

Commit

Permalink
Merge pull request #566 from Nukesor/log-to-stderr
Browse files Browse the repository at this point in the history
change: Send all log output to stderr
  • Loading branch information
Nukesor authored Aug 26, 2024
2 parents c9279a8 + afa5b0a commit 1c5f4aa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ TLDR: The new task state representation is more verbose but significantly cleane
**Important: The Pueue daemon needs to be restarted and the state will be wiped clean.**
- **Breaking**: Streamlined `pueue log` parameters to behave the same way as `start`, `pause` or `kill`. [#509](https://github.com/Nukesor/pueue/issues/509)
- **Breaking**: Remove the `--children` commandline flags, that have been deprecated and no longer serve any function since `v3.0.0`.
- Send log output to `stderr` instead of `stdout` [#562](https://github.com/Nukesor/pueue/issues/562).
- Change default log level from error to warning [#562](https://github.com/Nukesor/pueue/issues/562).

### Add

Expand All @@ -59,6 +61,7 @@ TLDR: The new task state representation is more verbose but significantly cleane

- Fixed delay after sending process related commands from client. [#548](https://github.com/Nukesor/pueue/pull/548)
- Callback templating arguments were html escaped by accident. [#564](https://github.com/Nukesor/pueue/pull/564)
- Print incompatible version warning info as a log message instead of plain stdout input, which broke json outputs [#562](https://github.com/Nukesor/pueue/issues/562).

## \[3.4.1\] - 2024-06-04

Expand Down
22 changes: 16 additions & 6 deletions pueue/src/bin/pueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{bail, Context, Result};
use clap::{CommandFactory, Parser};
use clap_complete::{generate, generate_to, shells};
use log::warn;
use simplelog::{Config, ConfigBuilder, LevelFilter, SimpleLogger};
use simplelog::{Config, ConfigBuilder, LevelFilter, SimpleLogger, TermLogger, TerminalMode};

use pueue_lib::settings::Settings;

Expand Down Expand Up @@ -35,10 +35,10 @@ async fn main() -> Result<()> {

// Init the logger and set the verbosity level depending on the `-v` flags.
let level = match opt.verbose {
0 => LevelFilter::Error,
1 => LevelFilter::Warn,
2 => LevelFilter::Info,
_ => LevelFilter::Debug,
0 => LevelFilter::Warn,
1 => LevelFilter::Info,
2 => LevelFilter::Debug,
_ => LevelFilter::Trace,
};

// Try to initialize the logger with the timezone set to the Local time of the machine.
Expand All @@ -51,7 +51,17 @@ async fn main() -> Result<()> {
Ok(builder) => builder.build(),
};

SimpleLogger::init(level, logger_config).unwrap();
// Init a terminal logger. If this fails for some reason, try fallback to a SimpleLogger
if TermLogger::init(
level,
logger_config.clone(),
TerminalMode::Stderr,
simplelog::ColorChoice::Auto,
)
.is_err()
{
SimpleLogger::init(level, logger_config).unwrap();
}

// Try to read settings from the configuration file.
let (mut settings, config_found) =
Expand Down
22 changes: 16 additions & 6 deletions pueue/src/bin/pueued.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::process::Command;
use anyhow::Result;
use clap::Parser;
use log::warn;
use simplelog::{Config, ConfigBuilder, LevelFilter, SimpleLogger};
use simplelog::{Config, ConfigBuilder, LevelFilter, SimpleLogger, TermLogger, TerminalMode};

use pueue::daemon::cli::CliArguments;
use pueue::daemon::run;
Expand All @@ -19,10 +19,10 @@ async fn main() -> Result<()> {

// Set the verbosity level of the logger.
let level = match opt.verbose {
0 => LevelFilter::Error,
1 => LevelFilter::Warn,
2 => LevelFilter::Info,
_ => LevelFilter::Debug,
0 => LevelFilter::Warn,
1 => LevelFilter::Info,
2 => LevelFilter::Debug,
_ => LevelFilter::Trace,
};

// Try to initialize the logger with the timezone set to the Local time of the machine.
Expand All @@ -35,7 +35,17 @@ async fn main() -> Result<()> {
Ok(builder) => builder.build(),
};

SimpleLogger::init(level, logger_config).unwrap();
// Init a terminal logger. If this fails for some reason, try fallback to a SimpleLogger
if TermLogger::init(
level,
logger_config.clone(),
TerminalMode::Stderr,
simplelog::ColorChoice::Auto,
)
.is_err()
{
SimpleLogger::init(level, logger_config).unwrap();
}

run(opt.config, opt.profile, false).await
}
Expand Down
4 changes: 2 additions & 2 deletions pueue/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{borrow::Cow, collections::HashMap};
use anyhow::{bail, Context, Result};
use clap::crate_version;
use crossterm::tty::IsTty;
use log::error;
use log::{error, warn};

use pueue_lib::network::message::*;
use pueue_lib::network::protocol::*;
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Client {
};

if show_warning {
println!(
warn!(
"Different daemon version detected '{version}'. Consider restarting the daemon."
);
}
Expand Down

0 comments on commit 1c5f4aa

Please sign in to comment.