Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --logfile #2539

Merged
merged 4 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added
* 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))

### Changed
* improve syntax highlighting file detection [[@acuteenvy](https://github.com/acuteenvy)] ([#2524](https://github.com/extrawurst/gitui/pull/2524))
* After commit: jump back to unstaged area [[@tommady](https://github.com/tommady)] ([#2476](https://github.com/extrawurst/gitui/issues/2476))
Expand Down
29 changes: 20 additions & 9 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::bug_report;
use anyhow::{anyhow, Result};
use asyncgit::sync::RepoPath;
use clap::{
crate_authors, crate_description, crate_name, Arg,
Command as ClapApp,
builder::ArgPredicate, crate_authors, crate_description,
crate_name, Arg, Command as ClapApp,
};
use simplelog::{Config, LevelFilter, WriteLogger};
use std::{
Expand All @@ -28,7 +28,8 @@ pub fn process_cmdline() -> Result<CliArgs> {
std::process::exit(0);
}
if arg_matches.get_flag("logging") {
setup_logging()?;
let logfile = arg_matches.get_one::<String>("logfile");
setup_logging(logfile.map(PathBuf::from))?;
}

let workdir =
Expand Down Expand Up @@ -87,11 +88,16 @@ fn app() -> ClapApp {
)
.arg(
Arg::new("logging")
.help("Stores logging output into a cache directory")
.help("Store logging output into a file (in the cache directory by default)")
.short('l')
.long("logging")
.num_args(0),
.default_value_if("logfile", ArgPredicate::IsPresent, "true")
.action(clap::ArgAction::SetTrue),
)
.arg(Arg::new("logfile")
.help("Store logging output into the specified file (implies --logging)")
.long("logfile")
.value_name("LOG_FILE"))
.arg(
Arg::new("watcher")
.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.")
Expand Down Expand Up @@ -122,11 +128,16 @@ fn app() -> ClapApp {
)
}

fn setup_logging() -> Result<()> {
let mut path = get_app_cache_path()?;
path.push("gitui.log");
fn setup_logging(path_override: Option<PathBuf>) -> Result<()> {
let path = if let Some(path) = path_override {
path
} else {
let mut path = get_app_cache_path()?;
path.push("gitui.log");
path
};

println!("Logging enabled. log written to: {path:?}");
println!("Logging enabled. Log written to: {path:?}");

WriteLogger::init(
LevelFilter::Trace,
Expand Down
Loading