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

fix filter target log level #45

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "1.9.0"
version = "2.0.0"
edition = "2021"
authors = ["baoyachi <liaoymxsdl@gmail.com>"]
description = "A simple log. It's really simple use"
Expand Down Expand Up @@ -30,11 +30,12 @@ log = "0.4.11"
log4rs = { version = "1.1.1", default-features = false, features = ["all_components", "humantime", "serde", "serde-value", "yaml_format", "gzip"], optional = true }
once_cell = { version = "1.15.0", default-features = false, optional = true }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
winnow = "0.6.18"

[dependencies.simple-log-derive]
path = "derive"
optional = true
version = "1"
version = "2"

[dev-dependencies]
serde_json = "1"
Expand Down
4 changes: 3 additions & 1 deletion examples/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#[macro_use]
extern crate simple_log;

use log::Level;

fn main() -> Result<(), String> {
simple_log::console("debug")?;
simple_log::console(Level::Debug)?;

debug!("test console debug");
info!("test console info");
Expand Down
3 changes: 2 additions & 1 deletion examples/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
extern crate simple_log;

fn main() -> Result<(), String> {
simple_log::file("./log/file.log", "debug", 100, 10)?;
let path = "./log/file.log";
simple_log::file(path, log::Level::Debug, 100, 10)?;

debug!("test file debug");
info!("test file info");
Expand Down
30 changes: 27 additions & 3 deletions examples/filter_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,36 @@
#[macro_use]
extern crate simple_log;

use log::LevelFilter;
use simple_log::LogConfig;

fn main() -> Result<(), String> {
let config = r#"
level = "debug"
level = "debug,filter_module::app::ctrl=warn,filter_module::app::launch::conf=error"
out_kind = "console"
time_format = "%H:%M:%S.%f"
filter_module = ["filter_module::app::ctrl","filter_module::app::launch::conf"]
"#;
let conf: LogConfig = toml::from_str(config).unwrap();

assert_eq!(
conf,
LogConfig {
path: None,
directory: None,
level: (
LevelFilter::Debug,
vec![
("filter_module::app::ctrl", LevelFilter::Warn).into(),
("filter_module::app::launch::conf", LevelFilter::Error).into(),
]
),
size: 0,
out_kind: vec!["console".into()],
roll_count: 0,
time_format: Some("%H:%M:%S.%f".to_string()),
}
);

simple_log::new(conf).unwrap(); //init log

debug!("test console debug");
Expand All @@ -35,7 +54,8 @@ fn main() -> Result<(), String> {

app::init_app();
app::launch::init_launch();
app::launch::conf::err_conf(); // this log filter
app::launch::conf::err_conf();
app::launch::conf::debug_conf(); // this log filter
app::launch::parser::err_parser();
app::ctrl::init_ctrl(); // this log filter

Expand All @@ -56,6 +76,10 @@ pub(crate) mod app {
pub fn err_conf() {
error!("conf log")
}

pub fn debug_conf() {
debug!("conf log")
}
}

pub mod parser {
Expand Down
2 changes: 1 addition & 1 deletion examples/get_log_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() -> Result<(), String> {
.path("./log/builder_log.log")
.size(100)
.roll_count(10)
.level("debug")
.level("debug")?
.output_file()
.output_console()
.build();
Expand Down
12 changes: 12 additions & 0 deletions examples/json_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ extern crate simple_log;
use simple_log::LogConfig;

fn main() {
let config = r#"
{
"path":"./log/tmp.log",
"level":"debug",
"size":10,
"out_kind":"console",
"roll_count":10,
"time_format":"%H:%M:%S.%f"
}"#;
let log_config: LogConfig = serde_json::from_str(config).unwrap();
assert_eq!(log_config.out_kind, vec!["console".into()]);

let config = r#"
{
"path":"./log/tmp.log",
Expand Down
2 changes: 1 addition & 1 deletion examples/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() -> Result<(), String> {
.path("./log/builder_log.log")
.size(100)
.roll_count(10)
.level("debug")
.level("debug")?
.time_format("%Y-%m-%d %H:%M:%S.%f")
.output_file()
.output_console()
Expand Down
4 changes: 2 additions & 2 deletions examples/update_log_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() -> Result<(), String> {
.path("./log/builder_log.log")
.size(100)
.roll_count(10)
.level("debug")
.level("debug")?
.output_file()
.output_console()
.build();
Expand All @@ -33,7 +33,7 @@ fn main() -> Result<(), String> {
.path("./log/builder_log.log")
.size(2)
.roll_count(2)
.level("info")
.level("info")?
.output_file()
.output_console()
.build();
Expand Down
Loading
Loading