@@ -68,15 +68,29 @@ enum Commands { |
| 68 | 68 | fn main() -> Result<()> { |
| 69 | 69 | let args = Args::parse(); |
| 70 | 70 | |
| 71 | | - // Initialize logging |
| 71 | + // Initialize logging (stderr + file at /tmp/garlock.log) |
| 72 | 72 | let log_level = if args.debug { "debug" } else { "info" }; |
| 73 | | - tracing_subscriber::registry() |
| 74 | | - .with( |
| 75 | | - EnvFilter::try_from_default_env() |
| 76 | | - .unwrap_or_else(|_| EnvFilter::new(log_level)), |
| 77 | | - ) |
| 78 | | - .with(tracing_subscriber::fmt::layer()) |
| 79 | | - .init(); |
| 73 | + let filter = EnvFilter::try_from_default_env() |
| 74 | + .unwrap_or_else(|_| EnvFilter::new(log_level)); |
| 75 | + let registry = tracing_subscriber::registry().with(filter); |
| 76 | + |
| 77 | + if let Ok(log_file) = std::fs::OpenOptions::new() |
| 78 | + .create(true) |
| 79 | + .append(true) |
| 80 | + .open("/tmp/garlock.log") |
| 81 | + { |
| 82 | + let file_layer = tracing_subscriber::fmt::layer() |
| 83 | + .with_writer(std::sync::Mutex::new(log_file)) |
| 84 | + .with_ansi(false); |
| 85 | + registry |
| 86 | + .with(tracing_subscriber::fmt::layer()) |
| 87 | + .with(file_layer) |
| 88 | + .init(); |
| 89 | + } else { |
| 90 | + registry |
| 91 | + .with(tracing_subscriber::fmt::layer()) |
| 92 | + .init(); |
| 93 | + } |
| 80 | 94 | |
| 81 | 95 | tracing::info!("garlock {} starting", env!("CARGO_PKG_VERSION")); |
| 82 | 96 | tracing::debug!(?args, "Command line arguments"); |
@@ -498,10 +512,11 @@ fn run_lock(config: Config) -> Result<()> { |
| 498 | 512 | match event { |
| 499 | 513 | x11rb::protocol::Event::KeyPress(key_event) => { |
| 500 | 514 | let keycode = key_event.detail; |
| 501 | | - tracing::debug!(keycode, "Key press"); |
| 515 | + tracing::info!(keycode, event_window = key_event.event, "Key press"); |
| 502 | 516 | |
| 503 | 517 | // Process key through XKB |
| 504 | 518 | let key_result = keyboard.process_key(keycode, true); |
| 519 | + tracing::info!(?key_result, "XKB key result"); |
| 505 | 520 | |
| 506 | 521 | match key_result { |
| 507 | 522 | #[cfg(feature = "dev")] |
@@ -552,6 +567,14 @@ fn run_lock(config: Config) -> Result<()> { |
| 552 | 567 | } |
| 553 | 568 | |
| 554 | 569 | KeyResult::Enter => { |
| 570 | + tracing::info!( |
| 571 | + pw_empty = password.is_empty(), |
| 572 | + pw_chars = password.char_count(), |
| 573 | + pw_bytes = password.len(), |
| 574 | + auth_pending = pending_auth.is_some(), |
| 575 | + in_cooldown = locker_state.is_in_cooldown(), |
| 576 | + "Enter pressed" |
| 577 | + ); |
| 555 | 578 | // Block attempts during cooldown |
| 556 | 579 | if locker_state.is_in_cooldown() { |
| 557 | 580 | let remaining = locker_state.cooldown_remaining(); |
@@ -568,6 +591,7 @@ fn run_lock(config: Config) -> Result<()> { |
| 568 | 591 | needs_redraw = true; |
| 569 | 592 | tracing::info!( |
| 570 | 593 | chars = password.char_count(), |
| 594 | + bytes = password.len(), |
| 571 | 595 | "Starting PAM authentication" |
| 572 | 596 | ); |
| 573 | 597 | |
@@ -578,6 +602,12 @@ fn run_lock(config: Config) -> Result<()> { |
| 578 | 602 | )); |
| 579 | 603 | password.clear(); |
| 580 | 604 | ring.clear_highlight(); |
| 605 | + } else { |
| 606 | + tracing::warn!( |
| 607 | + "Enter ignored: pw_empty={} auth_pending={}", |
| 608 | + password.is_empty(), |
| 609 | + pending_auth.is_some() |
| 610 | + ); |
| 581 | 611 | } |
| 582 | 612 | } |
| 583 | 613 | |
@@ -600,13 +630,21 @@ fn run_lock(config: Config) -> Result<()> { |
| 600 | 630 | keyboard.process_key(key_event.detail, false); |
| 601 | 631 | } |
| 602 | 632 | |
| 603 | | - x11rb::protocol::Event::Expose(_) => { |
| 604 | | - tracing::trace!("Expose event"); |
| 633 | + x11rb::protocol::Event::Expose(e) => { |
| 634 | + tracing::info!(x = e.x, y = e.y, w = e.width, h = e.height, "Expose event"); |
| 605 | 635 | needs_redraw = true; |
| 606 | 636 | } |
| 607 | 637 | |
| 638 | + x11rb::protocol::Event::FocusIn(e) => { |
| 639 | + tracing::info!(?e.mode, ?e.detail, "FocusIn"); |
| 640 | + } |
| 641 | + |
| 642 | + x11rb::protocol::Event::FocusOut(e) => { |
| 643 | + tracing::warn!(?e.mode, ?e.detail, "FocusOut - may lose keyboard!"); |
| 644 | + } |
| 645 | + |
| 608 | 646 | _ => { |
| 609 | | - tracing::trace!(?event, "Unhandled event"); |
| 647 | + tracing::debug!(?event, "Unhandled event"); |
| 610 | 648 | } |
| 611 | 649 | } |
| 612 | 650 | } |