Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional color and style support using paris crate #84

Merged
merged 8 commits into from Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -25,5 +25,5 @@ default = ["termcolor"]
[dependencies]
log = { version = "0.4.*", features = ["std"] }
termcolor = { version = "1.1.*", optional = true }
paris = { version = "*", optional = true }
paris = { version = "1.5.7", optional = true }
chrono = "0.4.1"
4 changes: 3 additions & 1 deletion src/lib.rs
Expand Up @@ -40,7 +40,9 @@ use log::Log;
use log::*;

#[cfg(feature = "paris")]
mod paris;
mod paris_macros;
#[cfg(feature = "paris")]
pub extern crate paris;
Drakulix marked this conversation as resolved.
Show resolved Hide resolved

/// Trait to have a common interface to obtain the Level of Loggers
///
Expand Down
39 changes: 0 additions & 39 deletions src/paris/mod.rs

This file was deleted.

130 changes: 130 additions & 0 deletions src/paris_macros/mod.rs
@@ -0,0 +1,130 @@
/// Logs a message at the info level.
///
/// Passed data uses a colorize_string formatter from a `paris` crate, so it can
/// contains special tags for controlling ANSI colors and styles
/// More info: https://docs.rs/paris/1.5.7/paris/formatter/fn.colorize_string.html
///
/// # Examples
///
/// ```edition2018
/// use log::info;
///
/// # fn main() {
/// # struct Connection { port: u32, speed: f32 }
/// let conn_info = Connection { port: 40, speed: 3.20 };
///
/// info!("Connected to port {} at {} Mb/s", conn_info.port, conn_info.speed);
/// info!(target: "connection_events", "Successfull connection, port: {}, speed: {}",
/// conn_info.port, conn_info.speed);
/// # }
/// ```
#[macro_export]
macro_rules! info {
($($args:tt)+) => {
log::info!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

/// Logs a message at the debug level.
///
/// Passed data uses a colorize_string formatter from a `paris` crate, so it can
/// contains special tags for controlling ANSI colors and styles
/// More info: https://docs.rs/paris/1.5.7/paris/formatter/fn.colorize_string.html
///
/// # Examples
///
/// ```edition2018
/// use log::debug;
///
/// # fn main() {
/// # struct Position { x: f32, y: f32 }
/// let pos = Position { x: 3.234, y: -1.223 };
///
/// debug!("New position: x: {}, y: {}", pos.x, pos.y);
/// debug!(target: "app_events", "New position: x: {}, y: {}", pos.x, pos.y);
/// # }
/// ```
#[macro_export]
macro_rules! debug {
($($args:tt)+) => {
log::debug!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

/// Logs a message at the trace level.
///
/// Passed data uses a colorize_string formatter from a `paris` crate, so it can
/// contains special tags for controlling ANSI colors and styles
/// More info: https://docs.rs/paris/1.5.7/paris/formatter/fn.colorize_string.html
///
/// # Examples
///
/// ```edition2018
/// use log::trace;
///
/// # fn main() {
/// # struct Position { x: f32, y: f32 }
/// let pos = Position { x: 3.234, y: -1.223 };
///
/// trace!("Position is: x: {}, y: {}", pos.x, pos.y);
/// trace!(target: "app_events", "x is {} and y is {}",
/// if pos.x >= 0.0 { "positive" } else { "negative" },
/// if pos.y >= 0.0 { "positive" } else { "negative" });
/// # }
/// ```
#[macro_export]
macro_rules! trace {
($($args:tt)+) => {
log::trace!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

/// Logs a message at the warn level.
///
/// Passed data uses a colorize_string formatter from a `paris` crate, so it can
/// contains special tags for controlling ANSI colors and styles
/// More info: https://docs.rs/paris/1.5.7/paris/formatter/fn.colorize_string.html
///
/// # Examples
///
/// ```edition2018
/// use log::warn;
///
/// # fn main() {
/// let warn_description = "Invalid Input";
///
/// warn!("Warning! {}!", warn_description);
/// warn!(target: "input_events", "App received warning: {}", warn_description);
/// # }
/// ```
#[macro_export]
macro_rules! warn {
($($args:tt)+) => {
log::warn!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}

/// Logs a message at the error level.
///
/// Passed data uses a colorize_string formatter from a `paris` crate, so it can
/// contains special tags for controlling ANSI colors and styles
/// More info: https://docs.rs/paris/1.5.7/paris/formatter/fn.colorize_string.html
///
/// # Examples
///
/// ```edition2018
/// use log::error;
///
/// # fn main() {
/// let (err_info, port) = ("No connection", 22);
///
/// error!("Error: {} on port {}", err_info, port);
/// error!(target: "app_events", "App Error: {}, Port: {}", err_info, 22);
/// # }
/// ```
#[macro_export]
macro_rules! error {
($($args:tt)+) => {
log::error!("{}", paris::formatter::colorize_string(format!($($args)*)));
};
}