Skip to content

Commit

Permalink
Replaced colored with owo-colors.
Browse files Browse the repository at this point in the history
Closes #3.
  • Loading branch information
oubiwann committed Mar 11, 2023
1 parent 3d9b74c commit 01e515b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
21 changes: 8 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ name = "twyg"

[dependencies]
chrono = { version = "0.4", default-features = false, features = ["clock"] }
colored = "2.0"
fern = { version = "0.6", features = ["colored"] }
log = "0.4"
owo-colors = "3.5.0"
serde = { version = "1.0", features = ["derive"] }
time = "0.3"

Expand Down
19 changes: 9 additions & 10 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::fmt::Arguments;
use std::str::FromStr;

use chrono;
use colored::*;
use fern::InitError;
use log;
use owo_colors::OwoColorize;
use serde::{Deserialize, Serialize};

/// A reference to the `LoggerOpts` struct is required as an argument to
Expand Down Expand Up @@ -36,18 +36,18 @@ fn get_opt_u32(x: Option<u32>) -> String {
}
}

fn colour_level(level: log::Level) -> colored::ColoredString {
fn colour_level(level: log::Level) -> String {
match level {
log::Level::Error => level.to_string().red(),
log::Level::Warn => level.to_string().bright_yellow(),
log::Level::Info => level.to_string().bright_green(),
log::Level::Debug => level.to_string().cyan(),
log::Level::Trace => level.to_string().bright_blue(),
log::Level::Error => level.to_string().red().to_string(),
log::Level::Warn => level.to_string().bright_yellow().to_string(),
log::Level::Info => level.to_string().bright_green().to_string(),
log::Level::Debug => level.to_string().cyan().to_string(),
log::Level::Trace => level.to_string().bright_blue().to_string(),
}
}

fn format_msg(msg: &Arguments<'_>) -> colored::ColoredString {
format!("{} {}", "▶".cyan(), msg).green()
fn format_msg(msg: &Arguments<'_>) -> String {
format!("{} {}", "▶".cyan(), msg).green().to_string()
}

fn get_report_caller_logger(opts: &LoggerOpts) -> fern::Dispatch {
Expand Down Expand Up @@ -130,7 +130,6 @@ fn get_logger(opts: &LoggerOpts) -> fern::Dispatch {
/// formatted according to your configuration and twyg.
///
pub fn setup_logger(opts: &LoggerOpts) -> Result<(), InitError> {
colored::control::set_override(opts.coloured);
let mut logger = if opts.report_caller {
get_report_caller_logger(opts)
} else {
Expand Down

0 comments on commit 01e515b

Please sign in to comment.