-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
235 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
.idea/.idea.gradle-util-rs.dir/.idea/projectSettingsUpdater.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
use std::io::Write; | ||
use termcolor::WriteColor; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct Logged; | ||
|
||
macro_rules! log_error { | ||
(target: $target:expr, $($arg:tt)+) => ({ | ||
log::log!(target: $target, log::Level::Error, $($arg)+); | ||
Logged | ||
}); | ||
($($arg:tt)+) => ({ | ||
log::log!(log::Level::Error, $($arg)+); | ||
Logged | ||
}); | ||
(target: $target:expr, $lvl:expr, $($arg:tt)+) => ({ | ||
log::log!(target: $target, $lvl, $($arg)+); | ||
Logged | ||
}); | ||
($lvl:expr, $($arg:tt)+) => ({ | ||
log::log!($lvl, $($arg)+); | ||
Logged | ||
}) | ||
} | ||
|
||
pub trait LoggedSideEffect { | ||
fn ignore_logged_error(self); | ||
} | ||
impl LoggedSideEffect for Result<(), Logged> { | ||
fn ignore_logged_error(self) {} | ||
} | ||
|
||
pub fn log_error(err: std::fmt::Arguments) -> Logged { | ||
let stderr = termcolor::StandardStream::stderr(termcolor::ColorChoice::Auto); | ||
let mut stderr = stderr.lock(); | ||
let _ = stderr.set_color(termcolor::ColorSpec::new().set_fg(Some(termcolor::Color::Red))); | ||
let _ = stderr.write(b"error"); | ||
let _ = stderr.reset(); | ||
let _ = writeln!(stderr, ": {}", err); | ||
Logged | ||
} | ||
|
||
pub fn log_error_with_timestamp(err: std::fmt::Arguments) -> Logged { | ||
let stderr = termcolor::StandardStream::stderr(termcolor::ColorChoice::Auto); | ||
let mut stderr = stderr.lock(); | ||
let _ = write!(stderr, "[{}]", chrono::Local::now()); | ||
let _ = stderr.set_color(termcolor::ColorSpec::new().set_fg(Some(termcolor::Color::Red))); | ||
let _ = stderr.write(b"error"); | ||
let _ = stderr.reset(); | ||
let _ = writeln!(stderr, ": {}", err); | ||
Logged | ||
} | ||
|
||
pub fn log_warn(warn: std::fmt::Arguments) { | ||
let stderr = termcolor::StandardStream::stderr(termcolor::ColorChoice::Auto); | ||
let mut stderr = stderr.lock(); | ||
let _ = stderr.set_color(termcolor::ColorSpec::new().set_fg(Some(termcolor::Color::Yellow))); | ||
let _ = stderr.write(b"warning"); | ||
let _ = stderr.reset(); | ||
let _ = writeln!(stderr, ": {}", warn); | ||
} | ||
|
||
pub mod chver; | ||
pub mod set_new; | ||
pub(crate) mod utils; |
Oops, something went wrong.