Skip to content

Commit

Permalink
Remove need for owo colors and add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEnder0 committed Jan 4, 2024
1 parent 0524dd6 commit 91bbd6c
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/logs
4 changes: 2 additions & 2 deletions .todo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[ ] Remove owo collors dependency
[x] Remove owo collors dependency
[ ] Make colors a feature flag
[ ] Create test cases
[x] Create test cases
[ ] Extend readme and documentation
[ ] Create better rs doc comments
104 changes: 77 additions & 27 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[package]
name = "scorched"
description = "A simple logging library for scorching all those pesky bugs."
version = "0.4.5"
version = "0.5.0"
edition = "2021"
license = "Apache-2.0"

[dependencies]
owo-colors = "3.5.0"
chrono = "0.4.31"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A simple logging library for scorching all those pesky bugs.

> [!NOTE]
> The current minimum supported Rust version is: 1.60.0 (Last checked on 12/13/2023)
> The current minimum supported Rust version is: 1.60.0 (Last checked on 1/3/2023)
## Example

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod macros;
mod utils;

mod test;

use std::{env, fmt::Debug, fs::OpenOptions, io::prelude::*};

use utils::{importance_tags::*, time_utils};
Expand Down
35 changes: 35 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::{log_this, logf, LogData, LogImportance};

#[test]
fn test_log_this() {
log_this(LogData {
importance: LogImportance::Error,
message: "Test error".to_string(),
});

log_this(LogData {
importance: LogImportance::Warning,
message: "Test warning".to_string(),
});

log_this(LogData {
importance: LogImportance::Info,
message: "Test info".to_string(),
});

log_this(LogData {
importance: LogImportance::Debug,
message: "Test debug".to_string(),
});
}

#[test]
fn test_logf() {
logf!(Error, "Test error");

logf!(Warning, "Test warning");

logf!(Info, "Test info");

logf!(Debug, "Test debug");
}
39 changes: 14 additions & 25 deletions src/utils/importance_tags.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
use owo_colors::{
colors::{css::*, CustomColor},
ComboColorDisplay, OwoColorize,
};
/// This file contains the tags for the different levels of importance.
/// These are pasted in front of the message when logging.
pub(crate) fn error_tag(
) -> ComboColorDisplay<'static, CustomColor<0, 0, 0>, CustomColor<{ u8::MAX }, 0, 0>, &'static str>
{
"[ERROR]".fg::<Black>().bg::<Red>()
/// Error tag displays red.
pub(crate) const fn error_tag() -> &'static str {
"\x1b[31m[ERROR]\x1b[0m"
}

pub(crate) fn warning_tag() -> ComboColorDisplay<
'static,
CustomColor<0, 0, 0>,
CustomColor<{ u8::MAX }, { u8::MAX }, 0>,
&'static str,
> {
"[WARNING]".fg::<Black>().bg::<Yellow>()
/// Warning tag displays yellow.
pub(crate) const fn warning_tag() -> &'static str {
"\x1b[33m[WARNING]\x1b[0m"
}

pub(crate) fn info_tag(
) -> ComboColorDisplay<'static, CustomColor<0, 0, 0>, CustomColor<211, 211, 211>, &'static str> {
"[INFO]".fg::<Black>().bg::<LightGray>()
/// Info tag displays light gray.
pub(crate) const fn info_tag() -> &'static str {
"\x1b[37m[INFO]\x1b[0m"
}

pub(crate) fn debug_tag() -> ComboColorDisplay<
'static,
CustomColor<0, 0, 0>,
CustomColor<{ u8::MAX }, 0, { u8::MAX }>,
&'static str,
> {
"[DEBUG]".fg::<Black>().bg::<Magenta>()
/// Debug tag displays pink.
pub(crate) const fn debug_tag() -> &'static str {
"\x1b[35m[DEBUG]\x1b[0m"
}

0 comments on commit 91bbd6c

Please sign in to comment.