aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Dürr <contact@christianduerr.com>2018-11-16 11:13:38 +0100
committerChristian Dürr <contact@christianduerr.com>2018-11-16 11:13:38 +0100
commitcb4d2c0a3b20adc4c0603dcfb9447e9ebf72eae5 (patch)
tree0dc4d8c62882e70a583c01770607ce3c47944048
parente66f23ad97c8df42192d07650109d42de3c767c9 (diff)
downloadalacritty-display-config-errors.tar.gz
alacritty-display-config-errors.zip
Add option for keeping log filesdisplay-config-errors
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
-rw-r--r--CHANGELOG.md3
-rw-r--r--alacritty-completions.bash2
-rw-r--r--alacritty-completions.fish3
-rw-r--r--alacritty-completions.zsh1
-rw-r--r--alacritty.man3
-rw-r--r--alacritty.yml3
-rw-r--r--alacritty_macos.yml3
-rw-r--r--alacritty_windows.yml3
-rw-r--r--src/cli.rs9
-rw-r--r--src/config.rs10
-rw-r--r--src/display.rs8
-rw-r--r--src/logging.rs17
-rw-r--r--src/main.rs12
13 files changed, 67 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 56968bb3..66d06eb5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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 f8ffc107..48c683e8 100644
--- a/alacritty-completions.bash
+++ b/alacritty-completions.bash
@@ -11,7 +11,7 @@ _alacritty()
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 516c8ea9..6ffaef4b 100644
--- a/alacritty-completions.fish
+++ b/alacritty-completions.fish
@@ -16,6 +16,9 @@ complete -c alacritty \
-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 d2cc0eea..be7123a1 100644
--- a/alacritty-completions.zsh
+++ b/alacritty-completions.zsh
@@ -9,6 +9,7 @@ _alacritty() {
"(-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 5baa5b82..983a8988 100644
--- a/alacritty.man
+++ b/alacritty.man
@@ -19,6 +19,9 @@ Enable automatic config reloading
.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 29f6f54b..43a56685 100644
--- a/alacritty.yml
+++ b/alacritty.yml
@@ -127,6 +127,9 @@ font:
# 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 355f21cf..eff759dd 100644
--- a/alacritty_macos.yml
+++ b/alacritty_macos.yml
@@ -122,6 +122,9 @@ font:
# 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 8be7ea52..1c3a05b3 100644
--- a/alacritty_windows.yml
+++ b/alacritty_windows.yml
@@ -105,6 +105,9 @@ font:
# 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 68f3f6e6..99728780 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -31,6 +31,7 @@ pub struct Options {
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 @@ impl Default for Options {
command: None,
working_dir: None,
config: None,
+ persistent_logging: false,
}
}
}
@@ -71,6 +73,9 @@ impl Options {
.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 @@ impl Options {
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 1837cdf1..8e680ebe 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -494,6 +494,10 @@ pub struct Config {
#[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 @@ impl Config {
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 b1e9bce2..3e077750 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -411,8 +411,8 @@ impl Display {
// 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 @@ impl Display {
});
} 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 bca8a7f0..66cd8ddd 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -22,7 +22,7 @@ use log::{self, Level};
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 @@ impl LoggerProxy {
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 @@ struct OnDemandLogFileProxy {
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 8035deb9..3f2f5615 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -85,8 +85,6 @@ fn main() {
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 load_config(options: &cli::Options) -> Config {
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 @@ fn run(
// 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 @@ fn run(
#[cfg(windows)]
unsafe { FreeConsole(); }
+ info!("Goodbye.");
+
+ if !options.persistent_logging && !config.persistent_logging() {
+ logger_proxy.delete_log();
+ }
+
Ok(())
}