Initial commit

This commit is contained in:
Thomas Forgione 2019-02-27 10:40:43 +01:00
parent c5a55098b6
commit e26bdf412e
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
6 changed files with 120 additions and 8 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "beautylog"
version = "0.1.0"
authors = ["Thomas Forgione <thomas@forgione.fr>"]
edition = "2018"
description = "A beautiful logger in rust"
license = "LGPL-3.0-only"
repository = "https://gitea.tforgione.fr/tforgione/beautylog"
[dependencies]
log = "0.4.6"
colored = "1.7.0"

12
LICENSE
View File

@ -13,38 +13,38 @@ by the additional permissions listed below.
0. Additional Definitions. 0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser General As used herein, "this License" refers to version 3 of the GNU Lesser General
Public License, and the "GNU GPL" refers to version 3 of the GNU General Public Public License, and the "GNU GPL" refers to version 3 of the GNU General Public
License. License.
"The Library" refers to a covered work governed by this License, other than "The Library" refers to a covered work governed by this License, other than
an Application or a Combined Work as defined below. an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided by the An "Application" is any work that makes use of an interface provided by the
Library, but which is not otherwise based on the Library. Defining a subclass Library, but which is not otherwise based on the Library. Defining a subclass
of a class defined by the Library is deemed a mode of using an interface provided of a class defined by the Library is deemed a mode of using an interface provided
by the Library. by the Library.
A "Combined Work" is a work produced by combining or linking an Application A "Combined Work" is a work produced by combining or linking an Application
with the Library. The particular version of the Library with which the Combined with the Library. The particular version of the Library with which the Combined
Work was made is also called the "Linked Version". Work was made is also called the "Linked Version".
The "Minimal Corresponding Source" for a Combined Work means the Corresponding The "Minimal Corresponding Source" for a Combined Work means the Corresponding
Source for the Combined Work, excluding any source code for portions of the Source for the Combined Work, excluding any source code for portions of the
Combined Work that, considered in isolation, are based on the Application, Combined Work that, considered in isolation, are based on the Application,
and not on the Linked Version. and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the object The "Corresponding Application Code" for a Combined Work means the object
code and/or source code for the Application, including any data and utility code and/or source code for the Application, including any data and utility

View File

@ -1,3 +1,30 @@
# beautylog # beautylof
*A beautiful logger in rust*.
This repository contains the beauty logger. It's based on the [log](https://crates.io/crates/log) crate.
It is made to be super simple and to mimic the output of rustup and cargo.
### Usage
``` rust
#[macro_use]
extern crate log;
fn main() {
beautylog::init(log::LevelFilter::Trace).ok();
info!("some information");
warn!("something went wrong");
debug!("some debug info");
trace!("yo");
error!("something went horribly wrong");
}
```
### How it looks like
![how it renders](https://gitea.tforgione.fr/attachments/3417667c-746d-4f7f-bb79-c4ffa4913281)
A beautiful logger in rust

14
examples/example.rs Normal file
View File

@ -0,0 +1,14 @@
#[macro_use]
extern crate log;
fn main() {
beautylog::init(log::LevelFilter::Trace).ok();
info!("some information");
warn!("something went wrong");
debug!("some debug info");
trace!("yo");
error!("something went horribly wrong");
}

56
src/lib.rs Normal file
View File

@ -0,0 +1,56 @@
//! This crate contains the beauty logger.
//!
//! It is made to be super simple and to mimic the output of rustup and cargo.
//! ### Usage:
//! ```
//! #[macro_use]
//! extern crate log;
//!
//! fn main() {
//!
//! beautylog::init(log::LevelFilter::Trace).ok();
//!
//! info!("some information");
//! warn!("something went wrong");
//! debug!("some debug info");
//! trace!("yo");
//! error!("something went horribly wrong");
//!
//! }
//! ```
//!
//! ### How it looks like
//! ![how it renders](https://gitea.tforgione.fr/attachments/3417667c-746d-4f7f-bb79-c4ffa4913281)
//!
use log::{Record, Level, Metadata, SetLoggerError, LevelFilter};
use colored::*;
struct BeautyLogger;
static LOGGER: BeautyLogger = BeautyLogger;
/// Initializes the beauty logger with the corresponding level filter.
pub fn init(level: LevelFilter) -> Result<(), SetLoggerError> {
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(level))
}
impl log::Log for BeautyLogger {
fn enabled(&self, _: &Metadata) -> bool {
true
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
match record.level() {
Level::Error => eprintln!("{} {}", "error:".bold().red(), record.args()),
Level::Warn => eprintln!("{} {}", "warning:".bold().yellow(), record.args()),
Level::Info => eprintln!("{} {}", "info:".bold(), record.args()),
Level::Debug => eprintln!("{} {}", "debug:".bold().blue(), record.args()),
Level::Trace => eprintln!("{} {}", "trace:".bold().cyan(), record.args()),
}
}
}
fn flush(&self) {}
}