Skip to content

Commit

Permalink
v0.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
MXWXZ committed Nov 12, 2024
1 parent 17db72f commit 07f8d86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.6
## Changes
1. Logger can use `handler` to configure custom handlers.

# 0.4.5
## Changes
1. Make features to be more configurable to reduce compilation size.
Expand Down
2 changes: 1 addition & 1 deletion actix-cloud/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "actix-cloud"
version = "0.4.5"
version = "0.4.6"
edition = "2021"
authors = ["MXWXZ <[email protected]>"]
description = "Actix Cloud is an all-in-one web framework based on Actix Web."
Expand Down
8 changes: 8 additions & 0 deletions actix-cloud/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl Logger {
pub type WriterFn = Box<dyn Fn(LogItem, Box<dyn Write>) -> Result<()> + Send>;
pub type FilterFn = Box<dyn Fn(&LogItem) -> bool + Send>;
pub type TransformerFn = Box<dyn Fn(LogItem) -> LogItem + Send>;
pub type HandlerFn = Box<dyn Fn(&Map<String, Value>) -> bool + Send>;

pub struct LoggerGuard {
stop_tx: UnboundedSender<()>,
Expand All @@ -156,6 +157,7 @@ pub struct LoggerBuilder {
transformer: Option<TransformerFn>,
json_writer: WriterFn,
color_writer: WriterFn,
handler: Option<HandlerFn>,
}

impl LoggerBuilder {
Expand Down Expand Up @@ -225,6 +227,7 @@ impl LoggerBuilder {
transformer: None,
json_writer: Box::new(Self::default_json_writer),
color_writer: Box::new(Self::default_color_writer),
handler: None,
}
}

Expand Down Expand Up @@ -290,6 +293,11 @@ impl LoggerBuilder {

let join = thread::spawn(move || {
let handler = |v: Map<String, Value>| {
if let Some(x) = &self.handler {
if !x(&v) {
return;
}
}
let mut item = LogItem::from_json(v);
let time = item.fields.remove("_time").unwrap_or_default().as_i64();
if self.json {
Expand Down

0 comments on commit 07f8d86

Please sign in to comment.