Skip to content

Commit

Permalink
derived traits for loglevel and added features for usinh with serde a…
Browse files Browse the repository at this point in the history
…nd clap
  • Loading branch information
mendelsshop committed May 8, 2024
1 parent 1555c75 commit 9a352fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ description = "A simple file logger for Rust"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
serde = ["dep:serde"]
clap = ["dep:clap"]

[dependencies]
dirs = "5.0.1"
flexi_logger = "0.28.0"
serde = { optional = true, version = "1.0.201", features = ["derive"]}
clap = { optional = true, version = "4.5.4", features = ["derive"]}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ The log file is located:
|Windows| %FOLDERID_LocalAppData%\program_name\log\program_nametime_stamp.log | C:\Users\username\AppData\Local\program_name\log\program_name_2020-05-01T12-34-56.log|
|Linux| $XDG_DATA_HOME/program_name/log/program_name_time_stamp.log |/home/username/.local/share/program_name/log/program_name_2020-05-01T12-34-56.log|
|macOS| $HOME/Library/Application Support/program_name/log/program_nametime_stamp.log |Users/username/Library/Application Support/program_name/log/program_name_2020-05-01T12-34-56.log|

## Optional features

- clap: enable clap parsing for LogLevel
- serde: enable serde serialization and deserialization on LogLevel
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![doc = include_str!("../README.md")]
use flexi_logger::{FlexiLoggerError, Logger};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "clap")]
use clap::Subcommand;
extern crate dirs;

use std::{fmt, path::PathBuf};
Expand Down Expand Up @@ -97,10 +102,15 @@ macro_rules! init_logger {
};
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "clap", derive(Subcommand))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
/// Used to set the minimum log level displayed in the log file.
pub enum LogLevel {
Trace,
Debug,
#[default]
/// Default log level
Info,
Warn,
Error,
Expand Down

0 comments on commit 9a352fa

Please sign in to comment.