Skip to content

Commit

Permalink
Updated logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mbwilding committed Dec 21, 2023
1 parent 1c50ca7 commit 7f733b3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 60 deletions.
5 changes: 2 additions & 3 deletions dygma-layer-switcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ eframe = { version = "0.24", default-features = false, features = [
"wgpu",
"persistence",
] }
egui_logger = "0.4"
image = "0.24"
lazy_static = "1.4"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serialport = "4.3"
single-instance = "0.3"
sysinfo = "0.30"
tracing = "0.1"
tracing-appender = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
windows = { version = "0.52", features = [
"Win32_Foundation",
"Win32_UI_Accessibility",
Expand Down
14 changes: 10 additions & 4 deletions dygma-layer-switcher/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use eframe::egui::{
};
use eframe::{egui, Frame, Storage};
use lazy_static::lazy_static;
use log::{trace, warn};
use std::sync::{Arc, Mutex};
use tracing::{trace, warn};

pub const MAX_LAYERS: u8 = 10;

Expand All @@ -20,9 +20,6 @@ lazy_static! {

impl DygmaLayerSwitcher {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
// This is also where you can customize the look and feel of egui using
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.

if let Some(storage) = cc.storage {
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
}
Expand Down Expand Up @@ -339,6 +336,15 @@ impl eframe::App for DygmaLayerSwitcher {
self.detect_configuration_changes();
self.top_panel(ctx);
self.central_panel(ctx);

egui::Window::new("Log")
.open(&mut self.logging)
.drag_to_scroll(true)
.title_bar(true)
.show(ctx, |ui| {
egui_logger::logger_ui(ui);
ctx.request_repaint();
});
}

fn save(&mut self, storage: &mut dyn Storage) {
Expand Down
4 changes: 2 additions & 2 deletions dygma-layer-switcher/src/focus.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{anyhow, bail, Result};
use log::{error, info, trace};
use serialport::{SerialPort, SerialPortType};
use std::io::Write;
use std::time::Duration;
use tracing::{debug, error, trace};

#[derive(Debug)]
pub struct SupportedDevice {
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Focus {
})
.collect();

debug!("Found devices: {:?}", found_devices);
info!("Found devices: {:?}", found_devices);

Ok(found_devices)
}
Expand Down
2 changes: 1 addition & 1 deletion dygma-layer-switcher/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::app::CONFIGURATION;
use crate::focus::Focus;
use crate::structs::{AppDetails, Configuration, Mode};
use lazy_static::lazy_static;
use log::{debug, error, info};
use std::sync::Mutex;
use sysinfo::System;
use tracing::{debug, error, info};

lazy_static! {
static ref SYSTEM: Mutex<System> = Mutex::new(System::new_all());
Expand Down
38 changes: 0 additions & 38 deletions dygma-layer-switcher/src/log.rs

This file was deleted.

3 changes: 1 addition & 2 deletions dygma-layer-switcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod focus;
mod helpers;
mod icon;
mod layer;
mod log;
mod single;
mod structs;
mod templates;
Expand Down Expand Up @@ -44,7 +43,7 @@ pub fn main() -> Result<()> {
Box::new(move |cc| {
let mut app = DygmaLayerSwitcher::new(cc);
app.configuration_changed = true;
log::init(app.logging);
egui_logger::init().unwrap();
windows::start(); // Creates a thread that listens for window focus changes.
Box::new(app)
}),
Expand Down
2 changes: 1 addition & 1 deletion dygma-layer-switcher/src/single.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::verbiage;
use anyhow::Result;
use log::error;
use single_instance::SingleInstance;
use tracing::error;

pub fn check() -> Result<()> {
let instance = SingleInstance::new(verbiage::APP_NAME)?;
Expand Down
11 changes: 8 additions & 3 deletions dygma-layer-switcher/src/structs.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::app::MAX_LAYERS;
use crate::focus::Focus;
use crate::focus::{Device, Focus};
use crate::verbiage;
use log::error;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
use tracing::error;

#[derive(Deserialize, Serialize)]
#[serde(default)]
pub struct DygmaLayerSwitcher {
#[serde(skip)]
pub logging: bool,

pub port: String,
pub base_layer: u8,
pub mappings: BTreeMap<u8, Layer>,
Expand Down Expand Up @@ -36,7 +38,10 @@ impl Default for DygmaLayerSwitcher {
let focus = Focus::default();
let port = focus.find_first().unwrap_or_else(|_| {
error!("{}", verbiage::ERROR_NO_KEYBOARD);
std::process::exit(1);
Device {
name: verbiage::ERROR_NO_KEYBOARD,
port: verbiage::ERROR_NO_KEYBOARD.to_string(),
}
});

Self {
Expand Down
4 changes: 2 additions & 2 deletions dygma-layer-switcher/src/verbiage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const BUTTON_HIDDEN_LAYERS_UNHIDE_HINT: &str = "Unhide layer";
pub const BUTTON_REMOVE: &str = " - ";
pub const CHECKBOX_ACTIVE_HINT: &str = "Rule active?";
pub const EDIT_TEXT: &str = "Click to edit";
pub const ERROR_NO_KEYBOARD: &str = "Connect a Dygma keyboard and restart the application.";
pub const ERROR_NO_KEYBOARD: &str = "Connect a Dygma keyboard";
pub const EXCLUDES_HINT: &str = "Exclude a child process.";
pub const LAYER: &str = "Layer";
pub const MODE_PARENT: &str = "Parents";
Expand All @@ -31,7 +31,7 @@ pub const SETTING_BASE_LAYER_HINT: &str = "The layer to return to.";
pub const SETTING_BASE_LAYER_VALUE_HINT: &str = "Click and drag to change the base layer.";
pub const SETTING_HIDDEN_LAYERS: &str = "Hidden Layers";
pub const SETTING_LOGGING: &str = "Logging";
pub const SETTING_LOGGING_HINT: &str = "Enables logging to file. Restart required.";
pub const SETTING_LOGGING_HINT: &str = "Enables the logging window.";
pub const SETTING_PORT: &str = "Port";
pub const SETTING_PORT_HINT: &str = "The serial port to communicate with.";
pub const SETTING_PORT_INPUT_HINT: &str = "Click to edit the port.";
Expand Down
8 changes: 4 additions & 4 deletions dygma-layer-switcher/src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::layer;
use crate::structs::AppDetails;
use log::{error, info, trace};
use std::path::Path;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;
use tracing::{debug, error, trace};
use windows::core::PCWSTR;
use windows::Win32::{
Foundation::{HWND, MAX_PATH},
Expand All @@ -25,7 +25,7 @@ static DEBOUNCER: AtomicU32 = AtomicU32::new(0);

pub fn start() {
std::thread::spawn(|| unsafe {
debug!("Hooking");
info!("Initializing out-of-context hook");

let module_handle = GetModuleHandleW(PCWSTR::null()).unwrap_or_else(|e| {
error!("Failed to get module handle: {:?}", e);
Expand All @@ -42,7 +42,7 @@ pub fn start() {
WINEVENT_OUTOFCONTEXT,
);

debug!("Hooked");
info!("Initialized out-of-context hook");

let mut msg = MSG::default();

Expand Down Expand Up @@ -92,7 +92,7 @@ pub unsafe fn hydrate(window_handle: HWND) -> AppDetails {
process: get_process(window_handle),
};

debug!("{:?}", app_details);
info!("{:?}", app_details);

app_details
}
Expand Down

0 comments on commit 7f733b3

Please sign in to comment.