Skip to content

Commit

Permalink
Add command line parameter to specify log file
Browse files Browse the repository at this point in the history
I had the logs of my debug helix mixed in with the logs from the
production helix.

Add a `--logfile` command line argument to redirect any logs to other
files, making my debugging easier :-)
  • Loading branch information
hunger committed Sep 11, 2022
1 parent 0361217 commit 8f110b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Args {
pub build_grammars: bool,
pub split: Option<Layout>,
pub verbosity: u64,
pub log_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
}
Expand Down Expand Up @@ -48,6 +49,10 @@ impl Args {
Some(path) => args.config_file = Some(path.into()),
None => anyhow::bail!("--config must specify a path to read"),
},
"--logfile" => match argv.next().as_deref() {
Some(path) => args.log_file = Some(path.into()),
None => anyhow::bail!("--logfile must specify a path to write"),
},
arg if arg.starts_with("--") => {
anyhow::bail!("unexpected double dash argument: {}", arg)
}
Expand Down
2 changes: 2 additions & 0 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ FLAGS:
-g, --grammar {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml
-c, --config <file> Specifies a file to use for configuration
-v Increases logging verbosity each use for up to 3 times
--logfile Specifies a file to use for logging
(default file: {})
-V, --version Prints version information
--vsplit Splits all given files vertically into different windows
Expand Down Expand Up @@ -114,6 +115,7 @@ FLAGS:
return Ok(0);
}

let logpath = args.log_file.as_ref().map(|p| p.clone()).unwrap_or(logpath);
setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;

let config_dir = helix_loader::config_dir();
Expand Down

0 comments on commit 8f110b5

Please sign in to comment.