|
1 | | -# Logforth Project |
| 1 | +# Logforth |
2 | 2 |
|
3 | 3 | [![Crates.io][crates-badge]][crates-url] |
4 | 4 | [![Documentation][docs-badge]][docs-url] |
|
16 | 16 | [actions-badge]: https://github.com/fast/logforth/workflows/CI/badge.svg |
17 | 17 | [actions-url]:https://github.com/fast/logforth/actions?query=workflow%3ACI |
18 | 18 |
|
19 | | -## Overview |
| 19 | +Logforth is a flexible and easy-to-use logging framework for Rust applications. It allows you to configure multiple dispatches, filters, and appenders to customize your logging setup according to your needs. |
20 | 20 |
|
21 | | -A versatile and extensible logging implementation. |
| 21 | +## Features |
22 | 22 |
|
23 | | -## Usage |
| 23 | +- **Multiple Dispatches**: Configure different logging behaviors for different parts of your application. |
| 24 | +- **Flexible Filters**: Use built-in or custom filters to control which log records are processed. |
| 25 | +- **Various Appenders**: Output logs to stdout, stderr, files, or even send them to OpenTelemetry collectors. |
| 26 | +- **Custom Layouts**: Format log records using predefined layouts or create your own. |
24 | 27 |
|
25 | | -Add the dependencies to your `Cargo.toml` with: |
| 28 | +## Getting Started |
| 29 | + |
| 30 | +Add `log` and `logforth` to your `Cargo.toml`: |
26 | 31 |
|
27 | 32 | ```shell |
28 | 33 | cargo add log |
29 | 34 | cargo add logforth |
30 | 35 | ``` |
31 | 36 |
|
32 | | -... where [log](https://crates.io/crates/log) is the logging facade and [logforth](https://crates.io/crates/logforth) is the logging implementation. |
| 37 | +## Simple Usage |
33 | 38 |
|
34 | | -Then, you can use the logger with the simplest default setup: |
| 39 | +Set up a basic logger that outputs to stdout: |
35 | 40 |
|
36 | 41 | ```rust |
37 | 42 | fn main() { |
38 | | - logforth::stderr().apply(); |
| 43 | + logforth::stdout().apply(); |
| 44 | + |
| 45 | + log::info!("This is an info message."); |
| 46 | + log::debug!("This debug message will not be printed by default."); |
39 | 47 | } |
40 | 48 | ``` |
41 | 49 |
|
42 | | -Or configure the logger in a more fine-grained way: |
| 50 | +## Advanced Usage |
| 51 | + |
| 52 | +Configure multiple dispatches with different filters and appenders: |
43 | 53 |
|
44 | 54 | ```rust |
45 | | -use log::LevelFilter; |
46 | 55 | use logforth::append; |
| 56 | +use log::LevelFilter; |
47 | 57 |
|
48 | 58 | fn main() { |
49 | 59 | logforth::builder() |
50 | | - .dispatch(|d| d.filter(LevelFilter::Debug).append(append::Stderr::default())) |
51 | | - .dispatch(|d| d.filter(LevelFilter::Info).append(append::Stdout::default())) |
| 60 | + .dispatch(|d| d |
| 61 | + .filter(LevelFilter::Error) |
| 62 | + .append(append::Stderr::default())) |
| 63 | + .dispatch(|d| d |
| 64 | + .filter(LevelFilter::Info) |
| 65 | + .append(append::Stdout::default())) |
52 | 66 | .apply(); |
| 67 | + |
| 68 | + log::error!("This error will be logged to stderr."); |
| 69 | + log::info!("This info will be logged to stdout."); |
| 70 | + log::debug!("This debug message will not be logged."); |
53 | 71 | } |
54 | 72 | ``` |
55 | 73 |
|
|
0 commit comments