Skip to content

Commit bc789ad

Browse files
committed
feat: Use env_logger to not always print so many messages
1 parent 69cbaab commit bc789ad

File tree

12 files changed

+139
-38
lines changed

12 files changed

+139
-38
lines changed

Cargo.lock

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pango = { git = "https://github.com/pop-os/gtk-rs" }
2929
pangocairo = { git = "https://github.com/pop-os/gtk-rs" }
3030
serde = { version = "1.0", features = ["derive"] }
3131
serde_json = "1.0"
32+
log = "0.4.0"
33+
env_logger = "0.8.3"
3234

3335
[build-dependencies]
3436
gio = { git = "https://github.com/pop-os/gtk-rs" }

src/application/keyboard.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl ObjectImpl for KeyboardInner {
6262
.get_visible_child()
6363
.map(|c| c.downcast_ref::<KeyboardLayer>().unwrap().page());
6464

65-
println!("{:?}", page);
65+
debug!("{:?}", page);
6666
let last_layer = keyboard.layer();
6767
keyboard.inner().page.set(page.unwrap_or(Page::Layer1));
6868
if keyboard.layer() != last_layer {
@@ -79,9 +79,9 @@ impl ObjectImpl for KeyboardInner {
7979
..connect_value_changed(clone!(@weak keyboard => move |this| {
8080
let value = this.get_value() as i32;
8181
if let Err(err) = keyboard.board().set_brightness(value) {
82-
eprintln!("{}", err);
82+
error!("{}", err);
8383
}
84-
println!("{}", value);
84+
info!("{}", value);
8585
}));
8686
};
8787

@@ -229,21 +229,21 @@ impl Keyboard {
229229
let mut keys = layout.keys();
230230
for key in keys.iter_mut() {
231231
for layer in 0..2 {
232-
println!(" Layer {}", layer);
232+
debug!(" Layer {}", layer);
233233
let scancode = match board.keymap_get(layer, key.electrical.0, key.electrical.1) {
234234
Ok(value) => value,
235235
Err(err) => {
236-
eprintln!("Failed to read scancode: {:?}", err);
236+
error!("Failed to read scancode: {:?}", err);
237237
0
238238
}
239239
};
240-
println!(" Scancode: {:04X}", scancode);
240+
debug!(" Scancode: {:04X}", scancode);
241241

242242
let scancode_name = match layout.scancode_names.get(&scancode) {
243243
Some(some) => some.to_string(),
244244
None => String::new(),
245245
};
246-
println!(" Scancode Name: {}", scancode_name);
246+
debug!(" Scancode Name: {}", scancode_name);
247247

248248
key.scancodes.borrow_mut().push((scancode, scancode_name));
249249
}
@@ -260,7 +260,7 @@ impl Keyboard {
260260
let max_brightness = match keyboard.board().max_brightness() {
261261
Ok(value) => value as f64,
262262
Err(err) => {
263-
eprintln!("{}", err);
263+
error!("{}", err);
264264
100.0
265265
}
266266
};
@@ -272,7 +272,7 @@ impl Keyboard {
272272
let brightness = match keyboard.board().brightness() {
273273
Ok(value) => value as f64,
274274
Err(err) => {
275-
eprintln!("{}", err);
275+
error!("{}", err);
276276
0.0
277277
}
278278
};
@@ -366,7 +366,7 @@ impl Keyboard {
366366
if !found {
367367
return;
368368
}
369-
println!(
369+
info!(
370370
" set {}, {}, {} to {:04X}",
371371
layer,
372372
k.electrical.0,
@@ -379,7 +379,7 @@ impl Keyboard {
379379
k.electrical.1,
380380
k.scancodes.borrow_mut()[layer].0,
381381
) {
382-
eprintln!("Failed to set keymap: {:?}", err);
382+
error!("Failed to set keymap: {:?}", err);
383383
}
384384

385385
self.set_selected(self.selected());
@@ -535,7 +535,7 @@ impl Keyboard {
535535

536536
if let Some(i) = i {
537537
let k = &keys[i];
538-
println!("{:#?}", k);
538+
debug!("{:#?}", k);
539539
if let Some(layer) = self.layer() {
540540
if let Some((_scancode, scancode_name)) = keys[i].scancodes.borrow().get(layer) {
541541
picker.set_selected(Some(scancode_name.to_string()));

src/application/layout/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Layout {
102102
for i in &row.0 {
103103
match i {
104104
PhysicalKeyEnum::Meta(meta) => {
105-
println!("Key metadata {:?}", meta);
105+
debug!("Key metadata {:?}", meta);
106106
x += meta.x;
107107
y -= meta.y;
108108
w = meta.w.unwrap_or(w);
@@ -125,24 +125,24 @@ impl Layout {
125125
}
126126
}
127127
PhysicalKeyEnum::Name(name) => {
128-
println!("Key {}, {} = {:?}", x, y, name);
128+
debug!("Key {}, {} = {:?}", x, y, name);
129129

130130
let logical = (row_i as u8, col_i as u8);
131-
println!(" Logical: {:?}", logical);
131+
debug!(" Logical: {:?}", logical);
132132

133133
let row_char = char::from_digit(logical.0 as u32, 36)
134134
.expect("Failed to convert row to char");
135135
let col_char = char::from_digit(logical.1 as u32, 36)
136136
.expect("Failed to convert col to char");
137137
let logical_name = format!("K{}{}", row_char, col_char).to_uppercase();
138-
println!(" Logical Name: {}", logical_name);
138+
debug!(" Logical Name: {}", logical_name);
139139

140140
let electrical = self
141141
.layout
142142
.get(logical_name.as_str())
143143
//.expect("Failed to find electrical mapping");
144144
.unwrap_or(&(0, 0));
145-
println!(" Electrical: {:?}", electrical);
145+
debug!(" Electrical: {:?}", electrical);
146146

147147
keys.push(Key {
148148
logical,

src/application/main_window.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl ObjectImpl for MainWindowInner {
116116
impl WidgetImpl for MainWindowInner {
117117
fn destroy(&self, window: &MainWindow) {
118118
self.parent_destroy(window);
119-
eprintln!("Window close");
119+
info!("Window close");
120120
}
121121
}
122122
impl ContainerImpl for MainWindowInner {}
@@ -149,7 +149,7 @@ impl MainWindow {
149149
window.add_keyboard(daemon.clone(), board, i);
150150
}
151151
} else if window.inner().count.load(Ordering::Relaxed) == 0 {
152-
eprintln!("Failed to locate any keyboards, showing demo");
152+
error!("Failed to locate any keyboards, showing demo");
153153

154154
let daemon = Rc::new(DaemonDummy::new(
155155
vec!["system76/launch_alpha_2".to_string()],
@@ -191,18 +191,18 @@ impl MainWindow {
191191
self.insert_action_group("kbd", Some(keyboard.action_group()));
192192
}
193193
} else {
194-
eprintln!("Failed to locate layout for '{}'", board_name);
194+
error!("Failed to locate layout for '{}'", board_name);
195195
}
196196
}
197197
}
198198

199199
#[cfg(target_os = "linux")]
200200
fn daemon() -> Rc<dyn Daemon> {
201201
if unsafe { libc::geteuid() == 0 } {
202-
eprintln!("Already running as root");
202+
info!("Already running as root");
203203
Rc::new(DaemonServer::new_stdio().expect("Failed to create server"))
204204
} else {
205-
eprintln!("Not running as root, spawning daemon with pkexec");
205+
info!("Not running as root, spawning daemon with pkexec");
206206
Rc::new(DaemonClient::new_pkexec())
207207
}
208208
}

src/application/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ impl ApplicationImpl for ConfiguratorAppInner {
9999
self.parent_activate(app);
100100

101101
if let Some(window) = app.get_active_window() {
102-
//TODO
103-
eprintln!("Focusing current window");
102+
info!("Focusing current window");
104103
window.present();
105104
} else {
106105
let phony_board_names = &*self.phony_board_names;

src/application/picker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Picker {
165165
};
166166
let layer = kb.layer();
167167

168-
println!("Clicked {} layer {:?}", name, layer);
168+
info!("Clicked {} layer {:?}", name, layer);
169169
if let Some(i) = kb.selected() {
170170
if let Some(layer) = layer {
171171
kb.keymap_set(i, layer, &name);

src/choose_color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn choose_color<W: IsA<gtk::Widget>>(
3535

3636
color_wheel.connect_hs_changed(clone!(@weak preview => @default-panic, move |wheel| {
3737
if let Err(err) = board.set_color(wheel.hs().to_rgb()) {
38-
eprintln!("Failed to set keyboard color: {}", err);
38+
error!("Failed to set keyboard color: {}", err);
3939
}
4040
preview.queue_draw();
4141
}));

0 commit comments

Comments
 (0)