Add optional file logging and fix board offsets

Introduce --log CLI flag to enable logging to
war_in_tunnels.log via simplelog.
This commit is contained in:
2026-03-27 18:28:16 +01:00
parent b71130d3d6
commit a0186ea0cb
8 changed files with 74 additions and 2 deletions
+2
View File
@@ -1,2 +1,4 @@
/target /target
/result /result
war_in_tunnels.log
Generated
+43
View File
@@ -1245,6 +1245,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "simplelog"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16257adbfaef1ee58b1363bdc0664c9b8e1e30aed86049635fb5f147d065a9c0"
dependencies = [
"log",
"termcolor",
"time",
]
[[package]] [[package]]
name = "siphasher" name = "siphasher"
version = "1.0.2" version = "1.0.2"
@@ -1312,6 +1323,15 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "termcolor"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "terminfo" name = "terminfo"
version = "0.9.0" version = "0.9.0"
@@ -1422,12 +1442,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa",
"libc", "libc",
"num-conv", "num-conv",
"num_threads", "num_threads",
"powerfmt", "powerfmt",
"serde_core", "serde_core",
"time-core", "time-core",
"time-macros",
] ]
[[package]] [[package]]
@@ -1436,6 +1458,16 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca"
[[package]]
name = "time-macros"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215"
dependencies = [
"num-conv",
"time-core",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.19.0" version = "1.19.0"
@@ -1521,7 +1553,9 @@ name = "war_in_tunnels"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"log",
"ratatui", "ratatui",
"simplelog",
] ]
[[package]] [[package]]
@@ -1715,6 +1749,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
+3
View File
@@ -12,3 +12,6 @@ strip = true
[dependencies] [dependencies]
clap = { version = "4.5.53", features = ["derive"] } clap = { version = "4.5.53", features = ["derive"] }
ratatui = "0.30.0" ratatui = "0.30.0"
log = "0.4.29"
simplelog = "0.12.2"
+2 -2
View File
@@ -23,13 +23,13 @@ impl BoardWidget {
let rows: u16 = area_height / CELL_HIGHT; let rows: u16 = area_height / CELL_HIGHT;
let cols: u16 = area_width / CELL_WIDTH; let cols: u16 = area_width / CELL_WIDTH;
let h_max_offset: usize = if app.states.settings.map_height as u16 > rows { let v_max_offset: usize = if app.states.settings.map_height as u16 > rows {
app.states.settings.map_height as u16 - rows app.states.settings.map_height as u16 - rows
} else { } else {
0 0
} as usize; } as usize;
let v_max_offset: usize = if app.states.settings.map_width as u16 > cols { let h_max_offset: usize = if app.states.settings.map_width as u16 > cols {
app.states.settings.map_width as u16 - cols app.states.settings.map_width as u16 - cols
} else { } else {
0 0
+7
View File
@@ -97,6 +97,13 @@ pub struct Cli {
default_value = "120" default_value = "120"
)] )]
pub skill_points_limit: u16, pub skill_points_limit: u16,
#[arg(
long,
help = "Enable logging to file (default: disabled)",
default_value_t = false
)]
pub log: bool,
} }
pub fn get_args() -> Cli { pub fn get_args() -> Cli {
+1
View File
@@ -1,2 +1,3 @@
pub mod app; pub mod app;
pub mod cli; pub mod cli;
pub mod logs;
+11
View File
@@ -0,0 +1,11 @@
use simplelog::{Config, LevelFilter, WriteLogger};
use std::fs::File;
pub fn init_logger() {
WriteLogger::init(
LevelFilter::Info,
Config::default(),
File::create("war_in_tunnels.log").expect("Failed to create log file"),
)
.expect("Failed to initialize logger");
}
+5
View File
@@ -7,10 +7,15 @@ use std::{
use war_in_tunnels::{ use war_in_tunnels::{
app::{App, Event, handle_input_events}, app::{App, Event, handle_input_events},
cli::{Cli, get_args}, cli::{Cli, get_args},
logs::init_logger,
}; };
fn main() -> Result<()> { fn main() -> Result<()> {
let args: Cli = get_args(); let args: Cli = get_args();
if args.log {
init_logger();
}
let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init(); let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init();
let mut app: App = App::new(args); let mut app: App = App::new(args);