How to use
[]
= "1.4"
use Logger;
let mut log = new;
log.info;
Optional features
Timestamps
If you'd like timestamps with all your logs you'll have to enable the feature when adding the crate as a dependency.
Notice: This will also include chrono
as a dependency.
[]
= { = "1.4", = ["timestamps"] }
Macros
Every common function has a macro. To make use of these macros you'll need to enable the macros feature.
[]
= { = "1.4", = ["macros"] }
No logger
If you'd prefer to only use the macros and not even have
the Logger
struct included in your package, that's definitely possible!
All you need to do is enable the no_logger
feature.
[]
= { = "1.4", = ["no_logger"] }
Simple API
// You can have icons at the start of your message!
log.info;
log.error;
// or as macros
info!;
error!;
See the Logger struct for all methods and their macro equivalents
Macros
With the macros feature enabled, you get access to macro equivalents of the logger functions.
Advantages of using macros:
- You don't have to instantiate the logger
Logger::new()
- Simple to write
- Can format parameters like
print!
andprintln!
Disadvantages of using macros:
- Can't chain calls
- Manual newlines and tabs with
\n
and\t
- There's no loading animation for macros
You get to decide whether you want to use macros or not.
Every macro has the same functionality as its Logger
equivalent. Colors and icon keys work just the same.
See the Logger struct for all methods and their macro equivalents
Chaining
All methods can be chained together to build more intricate log/message combinations, in hopes of minimizing the chaos that every log string becomes when you have to concatenate a bunch of strings and add tabs and newlines everywhere.
log.info
.indent.warn
.newline
.success;
Customisation
Outputting text is cool. Outputting text with a colored icon at the start is even cooler! But this crate is all about customisation, about making the logs feel like home, if you will. Included in the crate are a variety of keys you can use to colorize your logs just the way you want them to be.
log.info;
log.warn;
log.info;
There's a key for all colors supported by the terminal (white, black, red, blue, magenta, etc.)
If you add the word on
to any of those colors, it becomes the
background color instead (on red, on blue, on green)
.
// How useful...
log.info;
Maybe you'd like to use your terminals brighter colors, if that's the case
you just have to add bright
to your tag. Makes sense.
log.info;
Scroll down for a full list of keys if you're not feeling confident in your ability to name colors. It happens.
Resetting
You've probably seen the </>
tag in the above logs. It's not there to
"close the previously opened tag" no no. You can open as many tags as you want
and only use </>
once, it's just the "reset everything to default" tag, You might
decide you don't ever want to use it. It's up to you.
However, resetting everything to default might not be what you want. Most of the time it'll be enough, but for those times when it isn't there are a few other tags such as:
<///>
only resets the background<//>
only reset the foreground
Color keys
To use a key just add the color name surrounded by <
, >
to your log string. Include spaces
or use underlines(_
) or dashes(-
) instead if you wish.
Foreground
black
, red
, green
, yellow
, blue
, cyan
, magenta
, white
Bright
bright black
, bright red
, bright green
, bright yellow
, bright blue
, bright cyan
, bright magenta
,
bright white
Background
on black
, on red
, on green
, on yellow
, on blue
, on cyan
, on magenta
, on white
Bright
on bright black
, on bright red
, on bright green
, on bright yellow
, on bright blue
, on bright cyan
,
on bright magenta
, on bright white
Styles
bold
(b
), underline
(u
), dimmed
(d
), italic
(i
)
Styles are a bit different, they all have their usual keys, the long and painful to write ones. But they also have shorthand keys (in parenthesis).
And while they all may reset using one of the reset keys above, if you're looking to turn off a specific
style you've opened, you can just use the exact same key but with a slash /
in front of it.
Example: <bold>
gets closed by </bold>
Icons
info
, cross
, warn
, tick
, heart