Crates.io | sign-logger |
lib.rs | sign-logger |
version | 0.1.0 |
source | src |
created_at | 2021-10-15 12:33:25.787358 |
updated_at | 2021-10-15 12:33:25.787358 |
description | The only logger youll ever need, inspired by sign-logger on NPM |
homepage | |
repository | https://github.com/BlazifyOrg/sign-logger-rs |
max_upload_size | |
id | 465445 |
size | 11,150 |
Rust edition
The best rust logger out there, framework logging support is on the horizon.
use sign_logger::*;
fn main() {
let log = Logger::init(None, None, None);
log.info("This message will be underlined", Some(Overwrite {
title: "Info",
color: Colors::BLUE.resolve(),
underline: true,
date: OverwriteDate {
show: true,
format: "YY-MM-DD HH:MI"
}
}));
log.error("This message will have a modified date format", Some(Overwrite {
title: "Error",
color: Colors::RED.resolve(),
underline: false,
date: OverwriteDate {
show: true,
format: "YY-MM-DD"
}
}));
log.debug("This message will not show the date at all", Some(Overwrite {
title: "Error",
color: Colors::MAGENTA.resolve(),
underline: false,
date: OverwriteDate {
show: false,
format: ""
}
}));
log.fatal("This message is all default", None);
log.fatal("This message has a different colour than default", Some(Overwrite {
title: "Fatal",
color: Colors::YELLOW.resolve(),
underline: false,
date: OverwriteDate {
show: true,
format: "YY-MM-DD HH:MI"
}
}));
}
Output:
Implements Logger Struct
init(symbols: Option<(&'static str, &'static str)>, colors: Option<Coloring>, date: Option<&'static str>)
Example Usage:
Logger::init(Some(("[","]")), Some(Coloring {
fatal: Colors::YELLOW.resolve(),
error: Colors::BROWN.resolve(),
info: Colors::WHITE.resolve(),
debug: Colors::BLACK.resolve()
}), Some("YY-MM-DD"));
info(&self, message: &str, overwrite: Option<Overwrite>)
pub enum Colors {
UNDERLINE,
BLUE,
BROWN,
RED,
BLACK,
GREEN,
YELLOW,
MAGENTA,
CYAN,
WHITE,
RESET,
}
impl Colors {
pub fn resolve(&self) -> &'static str {
match self {
Self::UNDERLINE => "\u{001b}[4m",
Self::BLUE => "\u{001b}[34;1m",
Self::BROWN => "\u{001b}[0;33m",
Self::RED => "\u{001b}[31;1m",
Self::BLACK => "\u{001b}[30;1m",
Self::GREEN => "\u{001b}[32;1m",
Self::YELLOW => "\u{001b}[33;1m",
Self::MAGENTA => "\u{001b}[35;1m",
Self::CYAN => "\u{001b}[36;1m",
Self::WHITE => "\u{001b}[37;1m",
Self::RESET => "\u{001b}[0m",
}
}
}
pub struct Overwrite {
pub title: &'static str,
pub color: &'static str,
pub underline: bool,
pub date: OverwriteDate,
}
Example usage:
Logger.fatal("This message has a different colour than default", Some(Overwrite {
title: "Fatal",
color: Colors::YELLOW.resolve(),
underline: false,
date: OverwriteDate {
show: true,
format: "YY-MM-DD HH:MI"
}
}));
pub struct Coloring {
pub fatal: &'static str,
pub error: &'static str,
pub info: &'static str,
pub debug: &'static str,
}
Example usage:
Logger::init(None, Some(Coloring {
fatal: Colors::RED.resolve(),
error: Colors::YELLOW.resolve(),
info: Colors::GREEN.resolve(),
debug: Colors::CYAN.resolve()
}), None);
pub struct OverwriteDate {
pub show: bool,
pub format: &'static str,
}
Example usage:
Logger.fatal("This message has a different colour than default", Some(Overwrite {
title: "Fatal",
color: Colors::YELLOW.resolve(),
underline: false,
date: OverwriteDate {
show: true,
format: "YY-MM-DD HH:MI"
}
}));