Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wyhaya/logs
A simple terminal logger
https://github.com/wyhaya/logs
log logger rust terminal
Last synced: 16 days ago
JSON representation
A simple terminal logger
- Host: GitHub
- URL: https://github.com/wyhaya/logs
- Owner: wyhaya
- Created: 2020-07-03T03:22:16.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-15T11:33:38.000Z (over 1 year ago)
- Last Synced: 2024-10-16T05:08:14.491Z (28 days ago)
- Topics: log, logger, rust, terminal
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# logs
[![Crates.io](https://img.shields.io/crates/v/logs.svg?style=flat-square)](https://crates.io/crates/logs)
[![docs.rs](https://img.shields.io/badge/docs-rs-informational.svg?style=flat-square)](https://docs.rs/logs)
![Crates.io](https://img.shields.io/crates/l/logs?style=flat-square)> A simple terminal logger
## Usage
Add this in your `Cargo.toml`:
```toml
[dependencies]
logs = "*"
```## Example
```rust
use logs::{debug, error, info, trace, warn, Logs};fn main() {
Logs::new().init();trace!("This is a trace log");
debug!("This is a debug log");
info!("This is a info log");
warn!("This is a warn log");
error!("This is a error log");
}
```Output:
```
2022-09-06T08:38:23.490 [TRACE] This is a trace log
2022-09-06T08:38:23.490 [DEBUG] This is a debug log
2022-09-06T08:38:23.490 [INFO ] This is a info log
2022-09-06T08:38:23.490 [WARN ] This is a warn log
2022-09-06T08:38:23.490 [ERROR] This is a error log
```## Options
```rust
use logs::{Logs, debug, error, LevelFilter};fn main() {
Logs::new()
// Show log level color
.color(true)
// Filter log target
.target("target")
// Filter log level
.level(LevelFilter::Info)
// Filter log level from `LOG` environment variable
.level_from_default_env()
.unwrap()
// Filter log level from `NAME` environment variable
.level_from_env("NAME")
.unwrap()
// Filter log level from str
.level_from_str("info")
.unwrap()
// Apply
.init();
}```