1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
//! Contains the ILogger trait that loggers can implement.
//!
//! The ILogger interface acts as a bridge between the application and the
//! specific logging functionality implemented in this example of the bridge
//! pattern.
/// Represents the ability to send logging messages to some kind of output,
/// which is dictated by the required implementation of ILogger::write_line().
pub trait ILogger {
/// Send a formatted line to the logger. Must be implemented by any struct
/// implementing the ILogger trait.
///
/// # Parameters
/// - loglevel
///
/// Level of logging ("TRACE", "INFO", "ERROR")
/// - message
///
/// Message to log
fn write_line(&mut self, loglevel: &str, message: &str);
/// Log trace messages to the configured output. A newline will always be
/// added to the message when writing to the log. Default behavior is to
/// send the message to ILogger::write_line().
///
/// # Parameters
/// - message
///
/// The message to write to the log.
fn log_trace(&mut self, message: &str) {
self.write_line("TRACE", message);
}
/// Log information messages to the configured output. A newline will
/// always be added to the message when writing to the log. Default
/// behavior is to send the message to ILogger::write_line().
///
/// # Parameters
/// - message
///
/// The message to write to the log.
fn log_info(&mut self, message: &str) {
self.write_line("INFO", message);
}
/// Log error messages to the configured output. A newline will always be
/// added to the message when writing to the log. Default behavior is to
/// send the message to ILogger::write_line().
///
/// # Parameters
/// - message
///
/// The message to write to the log.
fn log_error(&mut self, message: &str) {
self.write_line("ERROR", message);
}
}