Logging #26
@ -26,31 +26,33 @@ use LogMessageType::GenericWarn;
|
||||
/**
|
||||
* Logs the given message.
|
||||
*/
|
||||
pub fn log_message(msg: &LogMessage, conf: &LogSettings, file: &str, line: u32, column: u32) -> Result<(), io::Error> {
|
||||
pub fn log_message(
|
||||
msg: &LogMessage,
|
||||
conf: &LogSettings,
|
||||
file: &str,
|
||||
line: u32,
|
||||
column: u32,
|
||||
) -> Result<(), io::Error> {
|
||||
// Check if message may be logged according to config.
|
||||
let Some(log_line) = log_to_str(msg, conf, file, line, column) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
// Log to file
|
||||
match conf.path().as_ref()
|
||||
{
|
||||
None => {/* Do not log to file */}
|
||||
Some(p) =>
|
||||
{
|
||||
match conf.path().as_ref() {
|
||||
None => { /* Do not log to file */ }
|
||||
Some(p) => {
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(p);
|
||||
let mut file = match file
|
||||
{
|
||||
let mut file = match file {
|
||||
Ok(f) => f,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
match writeln!(file, "{log_line}")
|
||||
{
|
||||
Ok(_) => {},
|
||||
match writeln!(file, "{log_line}") {
|
||||
Ok(_) => {}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
@ -61,7 +63,7 @@ pub fn log_message(msg: &LogMessage, conf: &LogSettings, file: &str, line: u32,
|
||||
return writeln!(stdout, "{log_line}");
|
||||
} else if msg.1 >= Information && *conf.stdout() {
|
||||
let mut stderr = io::stderr().lock();
|
||||
return writeln!(stderr, "{log_line}")
|
||||
return writeln!(stderr, "{log_line}");
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
Reference in New Issue
Block a user