Struct paris::Logger

source ·
pub struct Logger<'a> { /* private fields */ }

Implementations§

source§

impl<'a> Logger<'a>

source

pub fn new() -> Self

Initializes a new logger

Example
use paris::Logger;
let logger = Logger::new();
source

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!()

source

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!()

source

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!()

source

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!()

source

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!()

source

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");
source

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);
source

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!");
source

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.

source

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!");
source

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</>");

Trait Implementations§

source§

impl<'a> Default for Logger<'a>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Logger<'a>

§

impl<'a> Send for Logger<'a>

§

impl<'a> Sync for Logger<'a>

§

impl<'a> Unpin for Logger<'a>

§

impl<'a> !UnwindSafe for Logger<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.