diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-11-17 14:39:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-17 14:39:13 +0000 |
commit | 6265ef91d5496461fcd1025b21323982f3e47085 (patch) | |
tree | d8ab17aac3c2833d5bb231a5346504c227a242f1 /src/config.rs | |
parent | ea637cde1c82ad971078671aff087236f3fb0fbd (diff) | |
download | alacritty-6265ef91d5496461fcd1025b21323982f3e47085.tar.gz alacritty-6265ef91d5496461fcd1025b21323982f3e47085.zip |
Display errors and warnings
To make sure that all error and information reporting to the user is
unified, all instances of `print!`, `eprint!`, `println!` and
`eprintln!` have been removed and replaced by logging.
When `RUST_LOG` is not specified, the default Alacritty logger now also
prints to both the stderr and a log file. The log file is only created
when a message is written to it and its name is printed to stdout the
first time it is used.
Whenever a warning or an error has been written to the log file/stderr,
a message is now displayed in Alacritty which points to the log file
where the full error is documented.
The message is cleared whenever the screen is cleared using either the
`clear` command or the `Ctrl+L` key binding.
To make sure that log files created by root don't prevent normal users
from interacting with them, the Alacritty log file is `/tmp/Alacritty-$PID.log`.
Since it's still possible that the log file can't be created, the UI
error/warning message now informs the user if the message was only
written to stderr. The reason why it couldn't be created is then printed
to stderr.
To make sure the deletion of the log file at runtime doesn't create any
issues, the file is re-created if a write is attempted without the file
being present.
To help with debugging Alacritty issues, a timestamp and the error
level are printed in all log messages.
All log messages now follow this format:
[YYYY-MM-DD HH:MM] [LEVEL] Message
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 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
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/src/config.rs b/src/config.rs index ee30c085..ae1ec897 100644 --- a/src/config.rs +++ b/src/config.rs @@ -73,7 +73,7 @@ fn deserialize_duration_ms<'a, D>(deserializer: D) -> ::std::result::Result<Dura match u64::deserialize(deserializer) { Ok(threshold_ms) => Ok(Duration::from_millis(threshold_ms)), Err(err) => { - eprintln!("problem with config: {}; Using default value", err); + error!("problem with config: {}; Using default value", err); Ok(default_threshold_ms()) }, } @@ -172,7 +172,7 @@ fn deserialize_visual_bell_duration<'a, D>(deserializer: D) -> ::std::result::Re match u16::deserialize(deserializer) { Ok(duration) => Ok(duration), Err(err) => { - eprintln!("problem with config: {}; Using default value", err); + error!("problem with config: {}; Using default value", err); Ok(default_visual_bell_duration()) }, } @@ -310,19 +310,19 @@ impl<'de> Deserialize<'de> for Decorations { "none" => Ok(Decorations::None), "full" => Ok(Decorations::Full), "true" => { - eprintln!("deprecated decorations boolean value, \ + error!("deprecated decorations boolean value, \ use one of transparent|buttonless|none|full instead; \ Falling back to \"full\""); Ok(Decorations::Full) }, "false" => { - eprintln!("deprecated decorations boolean value, \ + error!("deprecated decorations boolean value, \ use one of transparent|buttonless|none|full instead; \ Falling back to \"none\""); Ok(Decorations::None) }, _ => { - eprintln!("invalid decorations value: {}; Using default value", value); + error!("invalid decorations value: {}; Using default value", value); Ok(Decorations::Full) } } @@ -336,23 +336,23 @@ impl<'de> Deserialize<'de> for Decorations { "none" => Ok(Decorations::None), "full" => Ok(Decorations::Full), "true" => { - eprintln!("deprecated decorations boolean value, \ + error!("deprecated decorations boolean value, \ use one of none|full instead; \ Falling back to \"full\""); Ok(Decorations::Full) }, "false" => { - eprintln!("deprecated decorations boolean value, \ + error!("deprecated decorations boolean value, \ use one of none|full instead; \ Falling back to \"none\""); Ok(Decorations::None) }, "transparent" | "buttonless" => { - eprintln!("macos-only decorations value: {}; Using default value", value); + error!("macos-only decorations value: {}; Using default value", value); Ok(Decorations::Full) }, _ => { - eprintln!("invalid decorations value: {}; Using default value", value); + error!("invalid decorations value: {}; Using default value", value); Ok(Decorations::Full) } } @@ -392,7 +392,7 @@ fn deserialize_padding<'a, D>(deserializer: D) -> ::std::result::Result<Delta<u8 match Delta::deserialize(deserializer) { Ok(delta) => Ok(delta), Err(err) => { - eprintln!("problem with config: {}; Using default value", err); + error!("problem with config: {}; Using default value", err); Ok(default_padding()) }, } @@ -503,6 +503,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>, @@ -528,7 +532,7 @@ fn failure_default_vec<'a, D, T>(deserializer: D) -> ::std::result::Result<Vec<T let vec = match Vec::<serde_yaml::Value>::deserialize(deserializer) { Ok(vec) => vec, Err(err) => { - eprintln!("problem with config: {}; Using empty vector", err); + error!("problem with config: {}; Using empty vector", err); return Ok(Vec::new()); }, }; @@ -539,7 +543,7 @@ fn failure_default_vec<'a, D, T>(deserializer: D) -> ::std::result::Result<Vec<T match T::deserialize(value) { Ok(binding) => bindings.push(binding), Err(err) => { - eprintln!("problem with config: {}; Skipping value", err); + error!("problem with config: {}; Skipping value", err); }, } } @@ -557,7 +561,7 @@ fn deserialize_tabspaces<'a, D>(deserializer: D) -> ::std::result::Result<usize, match usize::deserialize(deserializer) { Ok(value) => Ok(value), Err(err) => { - eprintln!("problem with config: {}; Using `8`", err); + error!("problem with config: {}; Using `8`", err); Ok(default_tabspaces()) }, } @@ -569,7 +573,7 @@ fn default_true_bool<'a, D>(deserializer: D) -> ::std::result::Result<bool, D::E match bool::deserialize(deserializer) { Ok(value) => Ok(value), Err(err) => { - eprintln!("problem with config: {}; Using `true`", err); + error!("problem with config: {}; Using `true`", err); Ok(true) }, } @@ -583,7 +587,7 @@ fn failure_default<'a, D, T>(deserializer: D) match T::deserialize(deserializer) { Ok(value) => Ok(value), Err(err) => { - eprintln!("problem with config: {}; Using default value", err); + error!("problem with config: {}; Using default value", err); Ok(T::default()) }, } @@ -645,7 +649,7 @@ fn deserialize_scrolling_history<'a, D>(deserializer: D) -> ::std::result::Resul match u32::deserialize(deserializer) { Ok(lines) => { if lines > MAX_SCROLLBACK_LINES { - eprintln!( + error!( "problem with config: scrollback size is {}, but expected a maximum of {}; \ Using {1} instead", lines, MAX_SCROLLBACK_LINES, @@ -656,7 +660,7 @@ fn deserialize_scrolling_history<'a, D>(deserializer: D) -> ::std::result::Resul } }, Err(err) => { - eprintln!("problem with config: {}; Using default value", err); + error!("problem with config: {}; Using default value", err); Ok(default_scrolling_history()) }, } @@ -668,7 +672,7 @@ fn deserialize_scrolling_multiplier<'a, D>(deserializer: D) -> ::std::result::Re match u8::deserialize(deserializer) { Ok(lines) => Ok(lines), Err(err) => { - eprintln!("problem with config: {}; Using default value", err); + error!("problem with config: {}; Using default value", err); Ok(default_scrolling_multiplier()) }, } @@ -710,7 +714,7 @@ impl<'a> de::Deserialize<'a> for ModsWrapper { "Shift" => res.shift = true, "Alt" | "Option" => res.alt = true, "Control" => res.ctrl = true, - _ => eprintln!("unknown modifier {:?}", modifier), + _ => error!("unknown modifier {:?}", modifier), } } @@ -831,7 +835,7 @@ impl<'a> de::Deserialize<'a> for ModeWrapper { "~AppCursor" => res.not_mode |= mode::TermMode::APP_CURSOR, "AppKeypad" => res.mode |= mode::TermMode::APP_KEYPAD, "~AppKeypad" => res.not_mode |= mode::TermMode::APP_KEYPAD, - _ => eprintln!("unknown mode {:?}", modifier), + _ => error!("unknown mode {:?}", modifier), } } @@ -1193,7 +1197,7 @@ fn deserialize_color_index<'a, D>(deserializer: D) -> ::std::result::Result<u8, match u8::deserialize(deserializer) { Ok(index) => { if index < 16 { - eprintln!( + error!( "problem with config: indexed_color's index is '{}', \ but a value bigger than 15 was expected; \ Ignoring setting", @@ -1207,7 +1211,7 @@ fn deserialize_color_index<'a, D>(deserializer: D) -> ::std::result::Result<u8, } }, Err(err) => { - eprintln!("problem with config: {}; Ignoring setting", err); + error!("problem with config: {}; Ignoring setting", err); // Return value out of range to ignore this color Ok(0) @@ -1262,7 +1266,7 @@ fn deserialize_optional_color<'a, D>(deserializer: D) -> ::std::result::Result<O }, Ok(None) => Ok(None), Err(err) => { - eprintln!("problem with config: {}; Using standard foreground color", err); + error!("problem with config: {}; Using standard foreground color", err); Ok(None) }, } @@ -1361,7 +1365,7 @@ fn rgb_from_hex<'a, D>(deserializer: D) -> ::std::result::Result<Rgb, D::Error> match rgb { Ok(rgb) => Ok(rgb), Err(err) => { - eprintln!("problem with config: {}; Using color #ff00ff", err); + error!("problem with config: {}; Using color #ff00ff", err); Ok(Rgb { r: 255, g: 0, b: 255 }) }, } @@ -1671,6 +1675,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())?; @@ -1701,24 +1711,22 @@ impl Config { } fn print_deprecation_warnings(&mut self) { - use ::util::fmt; if self.dimensions.is_some() { - eprintln!("{}", fmt::Yellow("Config `dimensions` is deprecated. \ - Please use `window.dimensions` instead.")); + warn!("{}", "Config `dimensions` is deprecated. \ + Please use `window.dimensions` instead."); } if self.padding.is_some() { - eprintln!("{}", fmt::Yellow("Config `padding` is deprecated. \ - Please use `window.padding` instead.")); + warn!("{}", "Config `padding` is deprecated. Please use `window.padding` instead."); } if self.mouse.faux_scrollback_lines.is_some() { - println!("{}", fmt::Yellow("Config `mouse.faux_scrollback_lines` is deprecated. \ - Please use `mouse.faux_scrolling_lines` instead.")); + warn!("{}", "Config `mouse.faux_scrollback_lines` is deprecated. \ + Please use `mouse.faux_scrolling_lines` instead."); } if let Some(custom_cursor_colors) = self.custom_cursor_colors { - eprintln!("{}", fmt::Yellow("Config `custom_cursor_colors` is deprecated.")); + warn!("{}", "Config `custom_cursor_colors` is deprecated."); if !custom_cursor_colors { self.colors.cursor.cursor = None; @@ -1727,18 +1735,17 @@ impl Config { } if self.cursor_style.is_some() { - eprintln!("{}", fmt::Yellow("Config `cursor_style` is deprecated. \ - Please use `cursor.style` instead.")); + warn!("{}", "Config `cursor_style` is deprecated. Please use `cursor.style` instead."); } if self.hide_cursor_when_typing.is_some() { - eprintln!("{}", fmt::Yellow("Config `hide_cursor_when_typing` is deprecated. \ - Please use `mouse.hide_when_typing` instead.")); + warn!("{}", "Config `hide_cursor_when_typing` is deprecated. \ + Please use `mouse.hide_when_typing` instead."); } if self.unfocused_hollow_cursor.is_some() { - eprintln!("{}", fmt::Yellow("Config `unfocused_hollow_cursor` is deprecated. \ - Please use `cursor.unfocused_hollow` instead.")); + warn!("{}", "Config `unfocused_hollow_cursor` is deprecated. \ + Please use `cursor.unfocused_hollow` instead."); } } } @@ -1839,7 +1846,7 @@ impl DeserializeSize for Size { match size { Ok(size) => Ok(size), Err(err) => { - eprintln!("problem with config: {}; Using size 12", err); + error!("problem with config: {}; Using size 12", err); Ok(Size::new(12.)) }, } @@ -2062,7 +2069,7 @@ impl Monitor { let _ = config_tx.send(config); handler.on_config_reload(); }, - Err(err) => eprintln!("Ignoring invalid config: {}", err), + Err(err) => error!("Ignoring invalid config: {}", err), } } } |