Skip to content

Commit 8c21073

Browse files
committed
feat: add audit layer directive
1 parent 7b69189 commit 8c21073

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

justfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ kvsd:
5353

5454
# Run api
5555
api:
56-
cd syndapi; RUST_LOG="syndapi=info,synd::feed::cache=debug,info" cargo run --features "introspection" -- \
56+
cd syndapi; RUST_LOG="info" cargo run --features "introspection" -- \
5757
--kvsd-host 127.0.0.1 --kvsd-port 7379 --kvsd-username {{kvsd_user}} --kvsd-password secret
5858

5959
# Run term

syndapi/src/main.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use tracing::{error, info};
22

33
use syndapi::{args, dependency::Dependency, serve::listen_and_serve};
4-
use tracing_subscriber::Layer;
54

65
fn init_tracing() {
76
use syndapi::serve::layer::audit;
87
use tracing_subscriber::{
9-
filter::EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt as _, Registry,
8+
filter::EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt as _, Layer as _,
9+
Registry,
1010
};
1111

1212
let color = {
@@ -28,7 +28,8 @@ fn init_tracing() {
2828
.with_filter(
2929
EnvFilter::try_from_default_env()
3030
.or_else(|_| EnvFilter::try_new("info"))
31-
.unwrap(),
31+
.unwrap()
32+
.add_directive(audit::Audit::directive()),
3233
),
3334
)
3435
.with(audit::layer())

syndapi/src/serve/layer/audit.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tracing::{
55
Event, Level, Metadata, Subscriber,
66
};
77
use tracing_subscriber::{
8-
filter::Filtered,
8+
filter::{Directive, Filtered},
99
layer::{self, Context},
1010
registry::LookupSpan,
1111
Layer,
@@ -47,6 +47,12 @@ impl Audit {
4747
pub const USER_ID: &'static str = "enduser.id";
4848
pub const OPERATION: &'static str = "operation";
4949
pub const RESULT: &'static str = "result";
50+
51+
pub fn directive() -> Directive {
52+
let directive = format!("{emit}=info", emit = Self::EMIT_TARGET);
53+
54+
directive.parse().expect("Invalid directive")
55+
}
5056
}
5157

5258
/// Create AuditLayer

0 commit comments

Comments
 (0)