Skip to content

Commit bfe9db6

Browse files
committed
logs: fix log levels and default log level, and adjust readme to reflect
1 parent 8709f7a commit bfe9db6

5 files changed

Lines changed: 25 additions & 20 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,16 @@ daemons.
7575
# Run as a daemon in the background with default configuration
7676
sudo watt
7777

78-
# Run with verbose logging
79-
sudo watt --verbose # or --quiet for decreased verbosity
78+
# Run with adjusted logging
79+
#
80+
# You can also use the logform options
81+
# --quiet and --verbose, and repeat them.
82+
sudo watt -qqq # Log level: OFF (won't log)
83+
sudo watt -qq # Log level: ERROR (will log only ERROR)
84+
sudo watt -q # Log level: WARN (will log ERROR and up)
85+
sudo watt # Log level: INFO (will log INFO and up)
86+
sudo watt -v # Log level: DEBUG (will log DEBUG and up)
87+
sudo watt -vv # Log level: TRACE (will log everything)
8088

8189
# Run with a custom configuration file
8290
sudo watt --config /path/to/config.toml

watt/config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,13 @@ impl DaemonConfig {
527527

528528
pub fn load_from(path: Option<&Path>) -> anyhow::Result<Self> {
529529
let contents = if let Some(path) = path {
530-
log::debug!("loading config from '{path}'", path = path.display());
530+
log::info!("loading config from '{path}'", path = path.display());
531531

532532
&fs::read_to_string(path).with_context(|| {
533533
format!("failed to read config from '{path}'", path = path.display())
534534
})?
535535
} else {
536-
log::debug!(
537-
"loading default config from embedded toml:\n{config}",
538-
config = Self::DEFAULT,
539-
);
536+
log::info!("loading default config");
540537

541538
Self::DEFAULT
542539
};

watt/daemon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Daemon {
7070
fn rescan(&mut self) -> anyhow::Result<()> {
7171
self.system.rescan()?;
7272

73-
log::debug!("appending daemon logs...");
73+
log::debug!("appending to daemon logs...");
7474

7575
let at = Instant::now();
7676

@@ -372,7 +372,7 @@ pub fn run(config: config::DaemonConfig) -> anyhow::Result<()> {
372372
minutes = delay.as_secs_f64() / 60.0,
373373
);
374374

375-
log::debug!("filtering rules and applying them...");
375+
log::info!("filtering rules and applying them...");
376376

377377
let start = Instant::now();
378378

watt/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum Command {
2525
/// Watt daemon.
2626
Watt {
2727
#[command(flatten)]
28-
verbosity: clap_verbosity_flag::Verbosity,
28+
verbosity: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
2929

3030
#[clap(flatten)]
3131
command: WattCommand,
@@ -34,7 +34,7 @@ pub enum Command {
3434
/// CPU metadata and modification utility.
3535
Cpu {
3636
#[command(flatten)]
37-
verbosity: clap_verbosity_flag::Verbosity,
37+
verbosity: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
3838

3939
#[clap(subcommand)]
4040
command: CpuCommand,
@@ -43,7 +43,7 @@ pub enum Command {
4343
/// Power supply metadata and modification utility.
4444
Power {
4545
#[command(flatten)]
46-
verbosity: clap_verbosity_flag::Verbosity,
46+
verbosity: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
4747

4848
#[clap(subcommand)]
4949
command: PowerCommand,
@@ -79,7 +79,7 @@ pub fn main() -> anyhow::Result<()> {
7979
| Command::Power { verbosity, .. }) = cli.command;
8080

8181
env_logger::Builder::new()
82-
.filter_level(verbosity.log_level_filter())
82+
.filter_level(dbg!(verbosity.log_level_filter()))
8383
.format_timestamp(None)
8484
.format_module_path(false)
8585
.init();

watt/system.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ impl System {
5050
}
5151

5252
pub fn rescan(&mut self) -> anyhow::Result<()> {
53-
log::debug!("rescanning view of system hardware...");
53+
log::info!("rescanning view of system hardware...");
5454

5555
{
5656
let start = Instant::now();
5757
self.cpus = cpu::Cpu::all().context("failed to scan CPUs")?;
58-
log::debug!(
58+
log::info!(
5959
"rescanned all CPUs in {millis}ms",
6060
millis = start.elapsed().as_millis(),
6161
);
@@ -65,7 +65,7 @@ impl System {
6565
let start = Instant::now();
6666
self.power_supplies = power_supply::PowerSupply::all()
6767
.context("failed to scan power supplies")?;
68-
log::debug!(
68+
log::info!(
6969
"rescanned all power supplies in {millis}ms",
7070
millis = start.elapsed().as_millis(),
7171
);
@@ -103,7 +103,7 @@ impl System {
103103
{
104104
let start = Instant::now();
105105
self.rescan_load_average()?;
106-
log::debug!(
106+
log::info!(
107107
"rescanned load average in {millis}ms",
108108
millis = start.elapsed().as_millis(),
109109
);
@@ -112,7 +112,7 @@ impl System {
112112
{
113113
let start = Instant::now();
114114
self.rescan_temperatures()?;
115-
log::debug!(
115+
log::info!(
116116
"rescanned temperatures in {millis}ms",
117117
millis = start.elapsed().as_millis(),
118118
);
@@ -164,7 +164,7 @@ impl System {
164164
if temperatures.is_empty() {
165165
const PATH: &str = "/sys/devices/virtual/thermal";
166166

167-
log::debug!(
167+
log::warn!(
168168
"failed to get CPU temperature information by using hwmon, falling \
169169
back to '{PATH}'"
170170
);
@@ -342,7 +342,7 @@ impl System {
342342
},
343343

344344
// Unknown, continue with other checks
345-
_ => log::debug!("unknown chassis type"),
345+
unknown => log::debug!("unknown chassis type: '{unknown}'"),
346346
}
347347
}
348348

0 commit comments

Comments
 (0)