Skip to content

Commit

Permalink
Add optional color and style support using paris crate
Browse files Browse the repository at this point in the history
More info about formatting:
https://github.com/0x20F/paris

When enabled you can use formatting like this:
info!("I can write <b>bold</b> text or use tags to <red>color it</>");
  • Loading branch information
manio committed Oct 25, 2021
1 parent aea22db commit 8eb25c1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -25,4 +25,5 @@ default = ["termcolor"]
[dependencies]
log = { version = "0.4.*", features = ["std"] }
termcolor = { version = "1.1.*", optional = true }
paris = { version = "*", optional = true }
chrono = "0.4.1"
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -61,6 +61,24 @@ simplelog = "^0.10.0"
```
to your `Cargo.toml`

## Color and style support

This crate can use a [paris](https://github.com/0x20F/paris) crate to provide support for color and styles.
To use this feature you need to set a paris feature, like this:
```
[dependencies]
simplelog = { version = "^0.10.0", features = ["paris"] }
```
in your `Cargo.toml`

After this you can use e.g. the following call:
```rust
info!("I can write <b>bold</b> text or use tags to <red>color it</>");
```

This will automatically generates ANSI terminal control sequences for required features.
More formatting info: [paris crate documentation](https://github.com/0x20F/paris)

## [Documentation](https://docs.rs/simplelog/)

## Contributing
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Expand Up @@ -39,6 +39,9 @@ use log::Log;
#[cfg(test)]
use log::*;

#[cfg(feature = "paris")]
mod paris;

/// Trait to have a common interface to obtain the Level of Loggers
///
/// Necessary for CombinedLogger to calculate
Expand Down
39 changes: 39 additions & 0 deletions src/paris/mod.rs
@@ -0,0 +1,39 @@
#[allow(missing_docs)]
#[macro_export]
macro_rules! info {
($($args:tt)+) => {
log::info!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

#[allow(missing_docs)]
#[macro_export]
macro_rules! debug {
($($args:tt)+) => {
log::debug!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

#[allow(missing_docs)]
#[macro_export]
macro_rules! trace {
($($args:tt)+) => {
log::trace!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

#[allow(missing_docs)]
#[macro_export]
macro_rules! warn {
($($args:tt)+) => {
log::warn!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

#[allow(missing_docs)]
#[macro_export]
macro_rules! error {
($($args:tt)+) => {
log::error!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

0 comments on commit 8eb25c1

Please sign in to comment.