Skip to content

Commit 4ccdeed

Browse files
Add --logfile (#2539)
Co-authored-by: extrawurst <[email protected]>
1 parent 1f3bd0f commit 4ccdeed

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
* new command-line option to override the default log file path (`--logfile`) [[@acuteenvy](https://github.com/acuteenvy)] ([#2539](https://github.com/gitui-org/gitui/pull/2539))
12+
1013
### Changed
1114
* improve syntax highlighting file detection [[@acuteenvy](https://github.com/acuteenvy)] ([#2524](https://github.com/extrawurst/gitui/pull/2524))
1215
* After commit: jump back to unstaged area [[@tommady](https://github.com/tommady)] ([#2476](https://github.com/extrawurst/gitui/issues/2476))

src/args.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::bug_report;
22
use anyhow::{anyhow, Result};
33
use asyncgit::sync::RepoPath;
44
use clap::{
5-
crate_authors, crate_description, crate_name, Arg,
6-
Command as ClapApp,
5+
builder::ArgPredicate, crate_authors, crate_description,
6+
crate_name, Arg, Command as ClapApp,
77
};
88
use simplelog::{Config, LevelFilter, WriteLogger};
99
use std::{
@@ -28,7 +28,8 @@ pub fn process_cmdline() -> Result<CliArgs> {
2828
std::process::exit(0);
2929
}
3030
if arg_matches.get_flag("logging") {
31-
setup_logging()?;
31+
let logfile = arg_matches.get_one::<String>("logfile");
32+
setup_logging(logfile.map(PathBuf::from))?;
3233
}
3334

3435
let workdir =
@@ -87,11 +88,16 @@ fn app() -> ClapApp {
8788
)
8889
.arg(
8990
Arg::new("logging")
90-
.help("Stores logging output into a cache directory")
91+
.help("Store logging output into a file (in the cache directory by default)")
9192
.short('l')
9293
.long("logging")
93-
.num_args(0),
94+
.default_value_if("logfile", ArgPredicate::IsPresent, "true")
95+
.action(clap::ArgAction::SetTrue),
9496
)
97+
.arg(Arg::new("logfile")
98+
.help("Store logging output into the specified file (implies --logging)")
99+
.long("logfile")
100+
.value_name("LOG_FILE"))
95101
.arg(
96102
Arg::new("watcher")
97103
.help("Use notify-based file system watcher instead of tick-based update. This is more performant, but can cause issues on some platforms. See https://github.com/extrawurst/gitui/blob/master/FAQ.md#watcher for details.")
@@ -122,11 +128,16 @@ fn app() -> ClapApp {
122128
)
123129
}
124130

125-
fn setup_logging() -> Result<()> {
126-
let mut path = get_app_cache_path()?;
127-
path.push("gitui.log");
131+
fn setup_logging(path_override: Option<PathBuf>) -> Result<()> {
132+
let path = if let Some(path) = path_override {
133+
path
134+
} else {
135+
let mut path = get_app_cache_path()?;
136+
path.push("gitui.log");
137+
path
138+
};
128139

129-
println!("Logging enabled. log written to: {path:?}");
140+
println!("Logging enabled. Log written to: {path:?}");
130141

131142
WriteLogger::init(
132143
LevelFilter::Trace,

0 commit comments

Comments
 (0)