log_error! macro to just log an error but with file and line

master
rasul 5 years ago
parent 532b0d0771
commit 428d6aeedd

@ -7,6 +7,7 @@ use crate::password::Password;
use crate::player::Player;
use crate::queue::SendQueue;
use crate::state::*;
use crate::log_error;
impl Game {
pub fn login(&mut self, token: Token, message: String, state: &Login) -> SendQueue {
@ -194,7 +195,7 @@ impl Game {
}
}
Ok(None) => {
log::error!("Player has no password: {}", player.id);
log_error!("Player has no password: {}", player.id);
send_queue.push(token, "Error\n", false, None);
send_queue.push(
token,
@ -204,7 +205,7 @@ impl Game {
);
}
Err(e) => {
log::error!("Database error: {}", e);
log_error!("Database error :: {}", e);
send_queue.push(token, "Error\n", false, None);
send_queue.push(
token,

@ -1,3 +1,12 @@
/// Log a message to the error log and add file and line.
#[macro_export]
macro_rules! log_error {
($($arg:tt)*) => {
let s = std::fmt::format(format_args!($($arg)*));
log::error!("{}({}) :: {}", file!(), line!(), s);
}
}
/// Unwrap a Result. If it's Err then log the error and provided format string
/// and return.
///

Loading…
Cancel
Save