pub struct Logger<'a> { /* private fields */ }
Implementations§
source§impl<'a> Logger<'a>
impl<'a> Logger<'a>
sourcepub fn log<T: Display>(&mut self, message: T) -> &mut Self
pub fn log<T: Display>(&mut self, message: T) -> &mut Self
Prints to stdout with no bells and whistles. I does however add a timestamp if enabled.
§Example
let mut logger = Logger::new();
logger.log("Basic and boring."); // Basic and boring.
Equivalent macro: log!()
sourcepub fn info<T: Display>(&mut self, message: T) -> &mut Self
pub fn info<T: Display>(&mut self, message: T) -> &mut Self
Prints to stdout and adds some info flair to the text
§Example
logger.info("This is some info");
Equivalent macro: info!()
sourcepub fn success<T: Display>(&mut self, message: T) -> &mut Self
pub fn success<T: Display>(&mut self, message: T) -> &mut Self
Prints to stdout and adds some success flair to text
§Example
logger.success("Everything went great!");
Equivalent macro: success!()
sourcepub fn warn<T: Display>(&mut self, message: T) -> &mut Self
pub fn warn<T: Display>(&mut self, message: T) -> &mut Self
Prints to stdout and adds some warning flare to text
§Example
logger.warn("This is a warning");
Equivalent macro: warn!()
sourcepub fn error<T: Display>(&mut self, message: T) -> &mut Self
pub fn error<T: Display>(&mut self, message: T) -> &mut Self
Prints to stderr and adds some error flare to text
§Example
logger.error("Something broke, here's the error");
Equivalent macro: error!()
sourcepub fn newline(&mut self, amount: usize) -> &mut Self
pub fn newline(&mut self, amount: usize) -> &mut Self
Prints a specified amount of newlines to stdout
§Example
logger
.newline(5)
.info("Some newlines before info")
.newline(2)
.info("And some more in between");
sourcepub fn indent(&mut self, amount: usize) -> &mut Self
pub fn indent(&mut self, amount: usize) -> &mut Self
Prints a specified amount of tabs to stdout
§Example
logger
.indent(1)
.warn("Indented warning eh? Stands out a bit")
.newline(5);
sourcepub fn loading<T: Display>(&mut self, message: T) -> &mut Self
pub fn loading<T: Display>(&mut self, message: T) -> &mut Self
Starts a loading animation with the given message.
§Example
let mut logger = Logger::new();
logger.loading("Counting to 52!");
// counting happens here (somehow)
logger
.done()
.success("Done counting, only took 1 million years");
That’s one way of doing it, but having to always call .done()
doesn’t
look that tidy. Well you don’t have to, unless you want. All other functions
(success, info, error, etc.) call .done()
just in case a loading thread is running
already. A cleaner example would be:
let mut logger = Logger::new();
logger.loading("Counting to 52! again");
// ....
logger.error("I give up, I can't do it again!");
sourcepub fn done(&mut self) -> &mut Self
pub fn done(&mut self) -> &mut Self
Stops the loading animation and clears the line so you can print something else when loading is done, maybe a success message. All other methods (success, warning, error, etc.) call this one automatically when called so you can use one of those directly for less clutter.
sourcepub fn same(&mut self) -> &mut Self
pub fn same(&mut self) -> &mut Self
Forces the next statement to not output a newline
§Example
logger
.same().log("This is on one line")
.indent(4)
.log("This is on the same line!");
sourcepub fn add_style(&mut self, key: &str, colors: Vec<&'a str>) -> &mut Self
pub fn add_style(&mut self, key: &str, colors: Vec<&'a str>) -> &mut Self
Add a custom key to the available list of keys
§Example
logger.add_style("lol", vec!["green", "bold", "on_blue"]);
// '<lol>' can now be used as a key in strings and will contain
// the defined colors and styles
logger.info("<lol>much shorter than writing all of them</>");