Skip to content

Commit c282712

Browse files
committed
Switch to debug! macro for quieter logs by default
1 parent 96c9465 commit c282712

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dbus-monitor/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ version = "0.0.1"
66
[dependencies]
77
dbus = { version = "0.9.7", features = ["vendored"] }
88
clap = { version = "4.0", features = ["derive"] }
9+
log = "0.4"
10+
env_logger = "0.10.0"
911

1012
[dependencies.libdbus-sys]
1113
default-features = false

dbus-monitor/src/dbus_monitor.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ use inputmodule_control::commands::ClapCli;
1919
use inputmodule_control::inputmodule::{serial_commands};
2020
use clap::{Parser, Subcommand};
2121

22+
use log::debug;
23+
2224
fn handle_message(msg: &Message) {
23-
println!("Got message from DBus: {:?}", msg);
25+
debug!("Got message from DBus: {:?}", msg);
26+
2427
let mut iter = msg.iter_init();
2528
while let Some(arg) = iter.get_refarg() {
26-
// Extract the inner value as a string and convert it to a String
2729
if let Some(string_ref) = arg.as_str() {
2830
let string_value: String = string_ref.to_string();
29-
println!("String value: {}", string_value);
31+
debug!("String value: {}", string_value);
3032

3133
if string_value.contains("calendar.google.com"){
3234
run_inputmodule_command(vec!["led-matrix", "--pattern", "all-on", "--blink-n-times", "3"]);
3335
run_inputmodule_command(vec!["led-matrix", "--brightness", "0"]);
3436
}
35-
} else {
36-
println!("Not a string.");
3737
}
3838
iter.next();
3939
}
4040

41-
println!("Message handled");
41+
debug!("DBus Message handled");
4242
}
4343

4444
pub fn run_inputmodule_command(args: Vec<&str>){
@@ -52,7 +52,7 @@ pub fn run_inputmodule_command(args: Vec<&str>){
5252
pub fn run_dbus_monitor() {
5353
// First open up a connection to the desired bus.
5454
let conn = Connection::new_session().expect("D-Bus connection failed");
55-
println!("Connection to DBus session monitor opened");
55+
debug!("Connection to DBus session monitor opened");
5656

5757
// Second create a rule to match messages we want to receive; in this example we add no
5858
// further requirements, so all messages will match
@@ -72,23 +72,23 @@ pub fn run_dbus_monitor() {
7272
"BecomeMonitor",
7373
(vec![rule.match_str()], 0u32),
7474
);
75-
println!("Monitoring DBus channel...");
75+
debug!("Monitoring DBus channel...");
7676

7777
match result {
7878
// BecomeMonitor was successful, start listening for messages
7979
Ok(_) => {
8080
conn.start_receive(
8181
rule,
8282
Box::new(|msg, _| {
83-
println!("Start listening");
83+
debug!("Start listening");
8484
handle_message(&msg);
8585
true
8686
}),
8787
);
8888
}
8989
// BecomeMonitor failed, fallback to using the old scheme
9090
Err(e) => {
91-
eprintln!(
91+
debug!(
9292
"Failed to BecomeMonitor: '{}', falling back to eavesdrop",
9393
e
9494
);
@@ -113,7 +113,7 @@ pub fn run_dbus_monitor() {
113113
// This can sometimes fail, for example when listening to the system bus as a non-root user.
114114
// So, just like `dbus-monitor`, we attempt to fallback without `eavesdrop=true`:
115115
Err(e) => {
116-
eprintln!("Failed to eavesdrop: '{}', trying without it", e);
116+
debug!("Failed to eavesdrop: '{}', trying without it", e);
117117
conn.add_match(rule, |_: (), _, msg| {
118118
handle_message(&msg);
119119
true

dbus-monitor/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
mod dbus_monitor;
22
mod utils;
33

4+
extern crate log;
5+
use log::{debug};
6+
use env_logger;
7+
48
fn main() {
9+
env_logger::init();
510
dbus_monitor::run_dbus_monitor();
611
}

0 commit comments

Comments
 (0)