Rust logging â
đŦ A couple of functions to make logging in Rust easier.
Installation đĻ
# Cargo.toml
[]
= "1.1.0"
Usage đ
Initializing
use *;
Logging
This code provides the following functions:
- đĄ warn(): Prints a warning message.
- đ´ error(): Prints an error message.
- đĩ info(): Prints an information message.
- đĸ success(): Prints a success message.
- âšī¸ Add a
f
before the function name to print the message to the log file
Each function takes a single parameter, which is the message to be printed.
logger.error;
logger.info;
logger.warn;
logger.success;
Highlighting đ
By default, the text after the colon is highlighted.
This can be disabled by setting the highlight
field to false
inside the custom settings.
let settings = LoggerOptions ;
let logger = settings.get_logger;
Icon connector đ
By default, the icon and the message are separated by an arrow ->
You can change this by setting the icon_connector
field to something else.
let settings = LoggerOptions
let logger = settings.get_logger;
Icons đ
By default, the following icons are used:
Icon | Function |
---|---|
[ x ] | error() |
[ i ] | info() |
[ v ] | success() |
[ ! ] | warn() |
You can change this by setting the following fields inside the custom settings:
let settings = LoggerOptions ;
let logger = settings.get_logger;
Custom Colors đ¨
You can change the colors of the messages by setting the colors
field inside the custom settings.
The value must be a rust_logging::Colors
struct.
let my_colors = Colors ;
let settings = LoggerOptions ;
let logger = settings.get_logger;
logger.error;
Log file đ
You can specify the log file path to write the messages to with the log_file
field.
Use the f
prefix before the function name to print the message to the log file.
let settings = LoggerOptions
let logger = settings.get_logger;
// -----------------------------
logger.fwarning;
logger.fsuccess;
logger.finfo;
logger.ferror;
also logging to terminal when logging to file đ
You can set environment variable LOG
to print
to also log to the terminal when logging to a file.
LOG=print
#########
# PROGRAM SOURCE CODE #
# ferror("This is an : error message");
#########
[
#########
# LOGFILE CONTENT #
# [ x ] -> This is an : error message
#########
final
If you have any problem, don't hesitate to open an issue
contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.