Add option for keeping log files Since it's not unusual to spawn a lot of different terminal emulators without restarting, Alacritty can create a ton of different log files. To combat this problem, logfiles are now removed by default after Alacritty has been closed. If the user wants to persist the log of a single session, the `--persistent_logging` option can be used. For persisting all log files, the `persistent_logging` option can be set in the configuration file
diff --git a/CHANGELOG.md b/CHANGELOG.md index 56968bb..66d06eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md
@@ -16,6 +16,9 @@ - Binaries for macOS, Windows and Debian-based systems are now published with GitHub releases - The keys F16-F24 have been added as options for key bindings - Display notice about errors and warnings inside Alacritty +- Log all messages to both stderr and a log file in the system's temporary directory +- New configuration option `persistent_logging` and CLI flag `--persistent-logging`, + for keeping the log file after closing Alacritty ### Changed
diff --git a/alacritty-completions.bash b/alacritty-completions.bash index f8ffc10..48c683e 100644 --- a/alacritty-completions.bash +++ b/alacritty-completions.bash
@@ -11,7 +11,7 @@ cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" prevprev="${COMP_WORDS[COMP_CWORD-2]}" - opts="-h --help -V --version --live-config-reload --no-live-config-reload --print-events -q -qq -v -vv -vvv --ref-test -e --command --config-file -d --dimensions -t --title --working-directory" + opts="-h --help -V --version --live-config-reload --no-live-config-reload --persistent-logging --print-events -q -qq -v -vv -vvv --ref-test -e --command --config-file -d --dimensions -t --title --working-directory" # If `--command` or `-e` is used, stop completing for i in "${!COMP_WORDS[@]}"; do
diff --git a/alacritty-completions.fish b/alacritty-completions.fish index 516c8ea..6ffaef4 100644 --- a/alacritty-completions.fish +++ b/alacritty-completions.fish
@@ -16,6 +16,9 @@ -l "no-live-config-reload" \ -d "Disable automatic config reloading" complete -c alacritty \ + -l "persistent-logging" \ + -d "Keep the log file after quitting Alacritty" +complete -c alacritty \ -f \ -l "config-file" \ -d "Specify an alternative config file"
diff --git a/alacritty-completions.zsh b/alacritty-completions.zsh index d2cc0ee..be7123a 100644 --- a/alacritty-completions.zsh +++ b/alacritty-completions.zsh
@@ -9,6 +9,7 @@ "(-V --version)"{-V,--version}"[Prints version information]" \ "(--no-live-config-reload)--live-config-reload[Enable automatic config reloading]" \ "(--live-config-reload)--no-live-config-reload[Disable automatic config reloading]" \ + "(--persistent-logging)--persistent-logging[Keep the log file after quitting Alacritty]" \ "--print-events[Print all events to stdout]" \ {-q,-qq}"[Reduces the level of verbosity (min is -qq)]" \ {-v,-vv,-vvv}"[Increases the level of verbosity (max is -vvv)]" \
diff --git a/alacritty.man b/alacritty.man index 5baa5b8..983a898 100644 --- a/alacritty.man +++ b/alacritty.man
@@ -19,6 +19,9 @@ .TP \fB\-\-no\-live\-config\-reload\fR Disable automatic config reloading +.TP +\fB\-\-persistent\-logging\fR +Keep the log file after quitting Alacritty .HP \fB\-\-print\-events\fR .TP
diff --git a/alacritty.yml b/alacritty.yml index 29f6f54..43a5668 100644 --- a/alacritty.yml +++ b/alacritty.yml
@@ -127,6 +127,9 @@ # Display the time it takes to redraw each frame. render_timer: false +# Keep the log file after quitting Alacritty. +persistent_logging: false + # If `true`, bold text is drawn using the bright color variants. draw_bold_text_with_bright_colors: true
diff --git a/alacritty_macos.yml b/alacritty_macos.yml index 355f21c..eff759d 100644 --- a/alacritty_macos.yml +++ b/alacritty_macos.yml
@@ -122,6 +122,9 @@ # Display the time it takes to redraw each frame. render_timer: false +# Keep the log file after quitting Alacritty. +persistent_logging: false + # If `true`, bold text is drawn using the bright color variants. draw_bold_text_with_bright_colors: true
diff --git a/alacritty_windows.yml b/alacritty_windows.yml index 8be7ea5..1c3a05b 100644 --- a/alacritty_windows.yml +++ b/alacritty_windows.yml
@@ -105,6 +105,9 @@ # Display the time it takes to redraw each frame. render_timer: false +# Keep the log file after quitting Alacritty. +persistent_logging: false + # Colors (Tomorrow Night Bright) colors: # Default colors
diff --git a/src/cli.rs b/src/cli.rs index 68f3f6e..9972878 100644 --- a/src/cli.rs +++ b/src/cli.rs
@@ -31,6 +31,7 @@ pub command: Option<Shell<'static>>, pub working_dir: Option<PathBuf>, pub config: Option<PathBuf>, + pub persistent_logging: bool, } impl Default for Options { @@ -46,6 +47,7 @@ command: None, working_dir: None, config: None, + persistent_logging: false, } } } @@ -71,6 +73,9 @@ .conflicts_with("live-config-reload")) .arg(Arg::with_name("print-events") .long("print-events")) + .arg(Arg::with_name("persistent-logging") + .long("persistent-logging") + .help("Keep the log file after quitting Alacritty")) .arg(Arg::with_name("dimensions") .long("dimensions") .short("d") @@ -129,6 +134,10 @@ options.live_config_reload = Some(false); } + if matches.is_present("persistent-logging") { + options.persistent_logging = true; + } + if let Some(mut dimensions) = matches.values_of("dimensions") { let width = dimensions.next().map(|w| w.parse().map(Column)); let height = dimensions.next().map(|h| h.parse().map(Line));
diff --git a/src/config.rs b/src/config.rs index 1837cdf..8e680eb 100644 --- a/src/config.rs +++ b/src/config.rs
@@ -494,6 +494,10 @@ #[serde(default, deserialize_with="failure_default")] cursor: Cursor, + /// Keep the log file after quitting + #[serde(default, deserialize_with="failure_default")] + persistent_logging: bool, + // TODO: DEPRECATED #[serde(default, deserialize_with = "failure_default")] custom_cursor_colors: Option<bool>, @@ -1662,6 +1666,12 @@ self.scrolling.history = history; } + /// Keep the log file after quitting Alacritty + #[inline] + pub fn persistent_logging(&self) -> bool { + self.persistent_logging + } + pub fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> { let path = path.into(); let raw = Config::read_file(path.as_path())?;
diff --git a/src/display.rs b/src/display.rs index b1e9bce..3e07775 100644 --- a/src/display.rs +++ b/src/display.rs
@@ -411,8 +411,8 @@ // Display errors and warnings if self.logger_proxy.errors() { let msg = match self.logger_proxy.log_path() { - Some(path) => format!(" ERROR: Full log at {} ", path), - None => " ERROR: Full log in stderr ".into(), + Some(path) => format!(" ERROR! See log at {} ", path), + None => " ERROR! See log in stderr ".into(), }; let color = Rgb { r: 0xff, @@ -424,8 +424,8 @@ }); } else if self.logger_proxy.warnings() { let msg = match self.logger_proxy.log_path() { - Some(path) => format!(" WARNING: Full log at {} ", path), - None => " WARNING: Full log in stderr ".into(), + Some(path) => format!(" WARNING! See log at {} ", path), + None => " WARNING! See log in stderr ".into(), }; let color = Rgb { r: 0xff,
diff --git a/src/logging.rs b/src/logging.rs index bca8a7f..66cd8dd 100644 --- a/src/logging.rs +++ b/src/logging.rs
@@ -22,7 +22,7 @@ use time; use std::env; -use std::fs::{File, OpenOptions}; +use std::fs::{self, File, OpenOptions}; use std::io::{self, LineWriter, Stdout, Write}; use std::path::PathBuf; use std::process; @@ -78,6 +78,10 @@ self.errors.store(false, Ordering::Relaxed); self.warnings.store(false, Ordering::Relaxed); } + + pub fn delete_log(&mut self) { + self.logfile_proxy.delete_log(); + } } struct Logger { @@ -154,6 +158,17 @@ path: String, } +impl OnDemandLogFileProxy { + fn delete_log(&mut self) { + if self.created.load(Ordering::Relaxed) { + if fs::remove_file(&self.path).is_ok() { + let _ = writeln!(io::stdout(), "Deleted log file at {:?}", self.path); + self.created.store(false, Ordering::Relaxed); + } + } + } +} + struct OnDemandLogFile { file: Option<LineWriter<File>>, created: Arc<AtomicBool>,
diff --git a/src/main.rs b/src/main.rs index 8035deb..3f2f561 100644 --- a/src/main.rs +++ b/src/main.rs
@@ -85,8 +85,6 @@ if let Err(err) = run(config, &options, logger_proxy) { die!("Alacritty encountered an unrecoverable error:\n\n\t{}\n", Red(err)); } - - info!("Goodbye."); } /// Load configuration @@ -115,7 +113,7 @@ fn run( mut config: Config, options: &cli::Options, - logger_proxy: LoggerProxy, + mut logger_proxy: LoggerProxy, ) -> Result<(), Box<Error>> { info!("Welcome to Alacritty."); if let Some(config_path) = config.path() { @@ -138,7 +136,7 @@ // This object contains all of the state about what's being displayed. It's // wrapped in a clonable mutex since both the I/O loop and display need to // access it. - let terminal = Term::new(&config, display.size().to_owned(), Some(logger_proxy)); + let terminal = Term::new(&config, display.size().to_owned(), Some(logger_proxy.clone())); let terminal = Arc::new(FairMutex::new(terminal)); // Find the window ID for setting $WINDOWID @@ -261,5 +259,11 @@ #[cfg(windows)] unsafe { FreeConsole(); } + info!("Goodbye."); + + if !options.persistent_logging && !config.persistent_logging() { + logger_proxy.delete_log(); + } + Ok(()) }