mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -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
|
||||
- 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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,6 +15,9 @@ complete -c alacritty \
|
|||
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" \
|
||||
|
|
|
@ -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)]" \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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())?;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>,
|
||||
|
|
12
src/main.rs
12
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue