aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-11-17 14:39:13 +0000
committerGitHub <noreply@github.com>2018-11-17 14:39:13 +0000
commit6265ef91d5496461fcd1025b21323982f3e47085 (patch)
treed8ab17aac3c2833d5bb231a5346504c227a242f1 /src/main.rs
parentea637cde1c82ad971078671aff087236f3fb0fbd (diff)
downloadalacritty-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/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 11adb396..a44c8eb3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -52,7 +52,7 @@ use alacritty::event;
use alacritty::event_loop::{self, EventLoop, Msg};
#[cfg(target_os = "macos")]
use alacritty::locale;
-use alacritty::logging;
+use alacritty::logging::{self, LoggerProxy};
use alacritty::sync::FairMutex;
use alacritty::term::Term;
use alacritty::tty::{self, process_should_exit};
@@ -65,8 +65,13 @@ fn main() {
#[cfg(windows)]
unsafe { AttachConsole(ATTACH_PARENT_PROCESS); }
- // Load command line options and config
+ // Load command line options
let options = cli::Options::load();
+
+ // Initialize the logger as soon as possible as to capture output from other subsystems
+ let logger_proxy = logging::initialize(&options).expect("Unable to initialize logger");
+
+ // Load configuration file
let config = load_config(&options).update_dynamic_title(&options);
// Switch to home directory
@@ -77,11 +82,9 @@ fn main() {
locale::set_locale_environment();
// Run alacritty
- if let Err(err) = run(config, &options) {
+ 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
@@ -98,7 +101,7 @@ fn load_config(options: &cli::Options) -> Config {
});
Config::load_from(&*config_path).unwrap_or_else(|err| {
- eprintln!("Error: {}; Loading default config", err);
+ error!("Error: {}; Loading default config", err);
Config::default()
})
}
@@ -107,10 +110,11 @@ fn load_config(options: &cli::Options) -> Config {
///
/// Creates a window, the terminal state, pty, I/O event loop, input processor,
/// config change monitor, and runs the main display loop.
-fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
- // Initialize the logger first as to capture output from other subsystems
- logging::initialize(options)?;
-
+fn run(
+ mut config: Config,
+ options: &cli::Options,
+ mut logger_proxy: LoggerProxy,
+) -> Result<(), Box<Error>> {
info!("Welcome to Alacritty.");
if let Some(config_path) = config.path() {
info!("Configuration loaded from {}", config_path.display());
@@ -122,7 +126,7 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
// Create a display.
//
// The display manages a window and can draw the terminal
- let mut display = Display::new(&config, options)?;
+ let mut display = Display::new(&config, options, logger_proxy.clone())?;
info!(
"PTY Dimensions: {:?} x {:?}",
@@ -135,7 +139,8 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
// 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());
+ let mut terminal = Term::new(&config, display.size().to_owned());
+ terminal.set_logger_proxy(logger_proxy.clone());
let terminal = Arc::new(FairMutex::new(terminal));
// Find the window ID for setting $WINDOWID
@@ -258,5 +263,11 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
#[cfg(windows)]
unsafe { FreeConsole(); }
+ info!("Goodbye.");
+
+ if !options.persistent_logging && !config.persistent_logging() {
+ logger_proxy.delete_log();
+ }
+
Ok(())
}