mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
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
This commit is contained in:
parent
e66f23ad97
commit
cb4d2c0a3b
13 changed files with 67 additions and 10 deletions
|
@ -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
|
- 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
|
- The keys F16-F24 have been added as options for key bindings
|
||||||
- Display notice about errors and warnings inside Alacritty
|
- 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
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ _alacritty()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
prevprev="${COMP_WORDS[COMP_CWORD-2]}"
|
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
|
# If `--command` or `-e` is used, stop completing
|
||||||
for i in "${!COMP_WORDS[@]}"; do
|
for i in "${!COMP_WORDS[@]}"; do
|
||||||
|
|
|
@ -15,6 +15,9 @@ complete -c alacritty \
|
||||||
complete -c alacritty \
|
complete -c alacritty \
|
||||||
-l "no-live-config-reload" \
|
-l "no-live-config-reload" \
|
||||||
-d "Disable automatic config reloading"
|
-d "Disable automatic config reloading"
|
||||||
|
complete -c alacritty \
|
||||||
|
-l "persistent-logging" \
|
||||||
|
-d "Keep the log file after quitting Alacritty"
|
||||||
complete -c alacritty \
|
complete -c alacritty \
|
||||||
-f \
|
-f \
|
||||||
-l "config-file" \
|
-l "config-file" \
|
||||||
|
|
|
@ -9,6 +9,7 @@ _alacritty() {
|
||||||
"(-V --version)"{-V,--version}"[Prints version information]" \
|
"(-V --version)"{-V,--version}"[Prints version information]" \
|
||||||
"(--no-live-config-reload)--live-config-reload[Enable automatic config reloading]" \
|
"(--no-live-config-reload)--live-config-reload[Enable automatic config reloading]" \
|
||||||
"(--live-config-reload)--no-live-config-reload[Disable 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]" \
|
"--print-events[Print all events to stdout]" \
|
||||||
{-q,-qq}"[Reduces the level of verbosity (min is -qq)]" \
|
{-q,-qq}"[Reduces the level of verbosity (min is -qq)]" \
|
||||||
{-v,-vv,-vvv}"[Increases the level of verbosity (max is -vvv)]" \
|
{-v,-vv,-vvv}"[Increases the level of verbosity (max is -vvv)]" \
|
||||||
|
|
|
@ -19,6 +19,9 @@ Enable automatic config reloading
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-no\-live\-config\-reload\fR
|
\fB\-\-no\-live\-config\-reload\fR
|
||||||
Disable automatic config reloading
|
Disable automatic config reloading
|
||||||
|
.TP
|
||||||
|
\fB\-\-persistent\-logging\fR
|
||||||
|
Keep the log file after quitting Alacritty
|
||||||
.HP
|
.HP
|
||||||
\fB\-\-print\-events\fR
|
\fB\-\-print\-events\fR
|
||||||
.TP
|
.TP
|
||||||
|
|
|
@ -127,6 +127,9 @@ font:
|
||||||
# Display the time it takes to redraw each frame.
|
# Display the time it takes to redraw each frame.
|
||||||
render_timer: false
|
render_timer: false
|
||||||
|
|
||||||
|
# Keep the log file after quitting Alacritty.
|
||||||
|
persistent_logging: false
|
||||||
|
|
||||||
# If `true`, bold text is drawn using the bright color variants.
|
# If `true`, bold text is drawn using the bright color variants.
|
||||||
draw_bold_text_with_bright_colors: true
|
draw_bold_text_with_bright_colors: true
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,9 @@ font:
|
||||||
# Display the time it takes to redraw each frame.
|
# Display the time it takes to redraw each frame.
|
||||||
render_timer: false
|
render_timer: false
|
||||||
|
|
||||||
|
# Keep the log file after quitting Alacritty.
|
||||||
|
persistent_logging: false
|
||||||
|
|
||||||
# If `true`, bold text is drawn using the bright color variants.
|
# If `true`, bold text is drawn using the bright color variants.
|
||||||
draw_bold_text_with_bright_colors: true
|
draw_bold_text_with_bright_colors: true
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,9 @@ font:
|
||||||
# Display the time it takes to redraw each frame.
|
# Display the time it takes to redraw each frame.
|
||||||
render_timer: false
|
render_timer: false
|
||||||
|
|
||||||
|
# Keep the log file after quitting Alacritty.
|
||||||
|
persistent_logging: false
|
||||||
|
|
||||||
# Colors (Tomorrow Night Bright)
|
# Colors (Tomorrow Night Bright)
|
||||||
colors:
|
colors:
|
||||||
# Default colors
|
# Default colors
|
||||||
|
|
|
@ -31,6 +31,7 @@ pub struct Options {
|
||||||
pub command: Option<Shell<'static>>,
|
pub command: Option<Shell<'static>>,
|
||||||
pub working_dir: Option<PathBuf>,
|
pub working_dir: Option<PathBuf>,
|
||||||
pub config: Option<PathBuf>,
|
pub config: Option<PathBuf>,
|
||||||
|
pub persistent_logging: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Options {
|
impl Default for Options {
|
||||||
|
@ -46,6 +47,7 @@ impl Default for Options {
|
||||||
command: None,
|
command: None,
|
||||||
working_dir: None,
|
working_dir: None,
|
||||||
config: None,
|
config: None,
|
||||||
|
persistent_logging: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +73,9 @@ impl Options {
|
||||||
.conflicts_with("live-config-reload"))
|
.conflicts_with("live-config-reload"))
|
||||||
.arg(Arg::with_name("print-events")
|
.arg(Arg::with_name("print-events")
|
||||||
.long("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")
|
.arg(Arg::with_name("dimensions")
|
||||||
.long("dimensions")
|
.long("dimensions")
|
||||||
.short("d")
|
.short("d")
|
||||||
|
@ -129,6 +134,10 @@ impl Options {
|
||||||
options.live_config_reload = Some(false);
|
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") {
|
if let Some(mut dimensions) = matches.values_of("dimensions") {
|
||||||
let width = dimensions.next().map(|w| w.parse().map(Column));
|
let width = dimensions.next().map(|w| w.parse().map(Column));
|
||||||
let height = dimensions.next().map(|h| h.parse().map(Line));
|
let height = dimensions.next().map(|h| h.parse().map(Line));
|
||||||
|
|
|
@ -494,6 +494,10 @@ pub struct Config {
|
||||||
#[serde(default, deserialize_with="failure_default")]
|
#[serde(default, deserialize_with="failure_default")]
|
||||||
cursor: Cursor,
|
cursor: Cursor,
|
||||||
|
|
||||||
|
/// Keep the log file after quitting
|
||||||
|
#[serde(default, deserialize_with="failure_default")]
|
||||||
|
persistent_logging: bool,
|
||||||
|
|
||||||
// TODO: DEPRECATED
|
// TODO: DEPRECATED
|
||||||
#[serde(default, deserialize_with = "failure_default")]
|
#[serde(default, deserialize_with = "failure_default")]
|
||||||
custom_cursor_colors: Option<bool>,
|
custom_cursor_colors: Option<bool>,
|
||||||
|
@ -1662,6 +1666,12 @@ impl Config {
|
||||||
self.scrolling.history = history;
|
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> {
|
pub fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let raw = Config::read_file(path.as_path())?;
|
let raw = Config::read_file(path.as_path())?;
|
||||||
|
|
|
@ -411,8 +411,8 @@ impl Display {
|
||||||
// Display errors and warnings
|
// Display errors and warnings
|
||||||
if self.logger_proxy.errors() {
|
if self.logger_proxy.errors() {
|
||||||
let msg = match self.logger_proxy.log_path() {
|
let msg = match self.logger_proxy.log_path() {
|
||||||
Some(path) => format!(" ERROR: Full log at {} ", path),
|
Some(path) => format!(" ERROR! See log at {} ", path),
|
||||||
None => " ERROR: Full log in stderr ".into(),
|
None => " ERROR! See log in stderr ".into(),
|
||||||
};
|
};
|
||||||
let color = Rgb {
|
let color = Rgb {
|
||||||
r: 0xff,
|
r: 0xff,
|
||||||
|
@ -424,8 +424,8 @@ impl Display {
|
||||||
});
|
});
|
||||||
} else if self.logger_proxy.warnings() {
|
} else if self.logger_proxy.warnings() {
|
||||||
let msg = match self.logger_proxy.log_path() {
|
let msg = match self.logger_proxy.log_path() {
|
||||||
Some(path) => format!(" WARNING: Full log at {} ", path),
|
Some(path) => format!(" WARNING! See log at {} ", path),
|
||||||
None => " WARNING: Full log in stderr ".into(),
|
None => " WARNING! See log in stderr ".into(),
|
||||||
};
|
};
|
||||||
let color = Rgb {
|
let color = Rgb {
|
||||||
r: 0xff,
|
r: 0xff,
|
||||||
|
|
|
@ -22,7 +22,7 @@ use log::{self, Level};
|
||||||
use time;
|
use time;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{self, File, OpenOptions};
|
||||||
use std::io::{self, LineWriter, Stdout, Write};
|
use std::io::{self, LineWriter, Stdout, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
@ -78,6 +78,10 @@ impl LoggerProxy {
|
||||||
self.errors.store(false, Ordering::Relaxed);
|
self.errors.store(false, Ordering::Relaxed);
|
||||||
self.warnings.store(false, Ordering::Relaxed);
|
self.warnings.store(false, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_log(&mut self) {
|
||||||
|
self.logfile_proxy.delete_log();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Logger {
|
struct Logger {
|
||||||
|
@ -154,6 +158,17 @@ struct OnDemandLogFileProxy {
|
||||||
path: String,
|
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 {
|
struct OnDemandLogFile {
|
||||||
file: Option<LineWriter<File>>,
|
file: Option<LineWriter<File>>,
|
||||||
created: Arc<AtomicBool>,
|
created: Arc<AtomicBool>,
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -85,8 +85,6 @@ fn main() {
|
||||||
if let Err(err) = run(config, &options, logger_proxy) {
|
if let Err(err) = run(config, &options, logger_proxy) {
|
||||||
die!("Alacritty encountered an unrecoverable error:\n\n\t{}\n", Red(err));
|
die!("Alacritty encountered an unrecoverable error:\n\n\t{}\n", Red(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Goodbye.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load configuration
|
/// Load configuration
|
||||||
|
@ -115,7 +113,7 @@ fn load_config(options: &cli::Options) -> Config {
|
||||||
fn run(
|
fn run(
|
||||||
mut config: Config,
|
mut config: Config,
|
||||||
options: &cli::Options,
|
options: &cli::Options,
|
||||||
logger_proxy: LoggerProxy,
|
mut logger_proxy: LoggerProxy,
|
||||||
) -> Result<(), Box<Error>> {
|
) -> Result<(), Box<Error>> {
|
||||||
info!("Welcome to Alacritty.");
|
info!("Welcome to Alacritty.");
|
||||||
if let Some(config_path) = config.path() {
|
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
|
// 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
|
// wrapped in a clonable mutex since both the I/O loop and display need to
|
||||||
// access it.
|
// 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));
|
let terminal = Arc::new(FairMutex::new(terminal));
|
||||||
|
|
||||||
// Find the window ID for setting $WINDOWID
|
// Find the window ID for setting $WINDOWID
|
||||||
|
@ -261,5 +259,11 @@ fn run(
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe { FreeConsole(); }
|
unsafe { FreeConsole(); }
|
||||||
|
|
||||||
|
info!("Goodbye.");
|
||||||
|
|
||||||
|
if !options.persistent_logging && !config.persistent_logging() {
|
||||||
|
logger_proxy.delete_log();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue