Skip to content

Commit

Permalink
helix-term: add config option for specifying log file
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Sharshakov <[email protected]>
  • Loading branch information
dsseng committed Aug 10, 2021
1 parent 27b551d commit a7a4608
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use serde::Deserialize;
use crate::keymap::Keymaps;

#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Config {
pub theme: Option<String>,
pub log_file: Option<String>,
#[serde(default)]
pub lsp: LspConfig,
#[serde(default)]
Expand Down
20 changes: 13 additions & 7 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {

#[tokio::main]
async fn main() -> Result<()> {
let cache_dir = helix_core::cache_dir();
if !cache_dir.exists() {
std::fs::create_dir_all(&cache_dir).ok();
}
let log_path_default = helix_core::cache_dir().join("helix.log");

let logpath = cache_dir.join("helix.log");
let help = format!(
"\
{} {}
Expand All @@ -63,7 +59,7 @@ FLAGS:
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_AUTHORS"),
env!("CARGO_PKG_DESCRIPTION"),
logpath.display(),
log_path_default.display(),
);

let args = Args::parse_args().context("could not parse arguments")?;
Expand All @@ -90,7 +86,17 @@ FLAGS:
Err(err) => return Err(Error::new(err)),
};

setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
let log_path = config
.log_file
.clone()
.map(PathBuf::from)
.unwrap_or(log_path_default);
let log_dir = log_path.parent().unwrap();

if !log_dir.exists() {
std::fs::create_dir_all(log_dir).ok();
}
setup_logging(log_path, args.verbosity).context("failed to initialize logging")?;

// TODO: use the thread local executor to spawn the application task separately from the work pool
let mut app = Application::new(args, config).context("unable to create new application")?;
Expand Down

0 comments on commit a7a4608

Please sign in to comment.