Commit 57a455e5 authored by Christian Duerr's avatar Christian Duerr Committed by GitHub

Ignore errors when logger can't write to output

The (e)print macro will panic when there is no output available to
write to, however in our scenario where we only log user errors to
stderr, the better choice would be to ignore when writing to stdout or
stderr is not possible.

This changes the (e)print macro to make use of `write` and ignore
any potential errors.

Since (e)println rely on (e)print, this also solves potential failuers
when calling (e)println.

With this change implemented, all of logging, (e)println and (e)print
should never fail even if the stdout/stderr is not available.
parent ddb9a558
......@@ -47,7 +47,7 @@ impl<T: Send + io::Write> log::Log for Logger<T> {
fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) && record.target().starts_with("alacritty") {
if let Ok(ref mut writer) = self.output.lock() {
writer.write_all(format!("{}\n", record.args()).as_ref()).expect("Error while logging!");
let _ = writer.write_all(format!("{}\n", record.args()).as_ref());
}
}
}
......
......@@ -29,3 +29,19 @@ macro_rules! maybe {
}
}
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => {{
use std::io::Write;
let _ = write!(::std::io::stdout(), $($arg)*);
}};
}
#[macro_export]
macro_rules! eprint {
($($arg:tt)*) => {{
use std::io::Write;
let _ = write!(::std::io::stderr(), $($arg)*);
}};
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment