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