Skip to content
Snippets Groups Projects
Commit 2e035654 authored by Dmitry Ivanov's avatar Dmitry Ivanov
Browse files

feat(audit): don't print None values

This patch adds a proper support for auxiliary fields containing `Option<T>`.
As of now, KV pairs containing `Some(x)` will be printed as just `x`,
while the ones with `None` won't be printed at all.

Example:

```rust
crate::audit!(
    message: "demo audit event",
    title: "example",
    severity: Low,
    test: Some(0u32),
);
```

```json
{
  "id": "1.0.1",
  "message": "demo audit event",
  "severity": "low",
  "time": "2023-12-06T17:16:51.085+0300",
  "title": "example",
  "test": "0"
}
```

```rust
crate::audit!(
    message: "demo audit event",
    title: "example",
    severity: Low,
    test: None::<i32>,
);
```

```json
{
  "id": "1.0.1",
  "message": "demo audit event",
  "severity": "low",
  "time": "2023-12-06T17:16:51.085+0300",
  "title": "example"
}
```
parent f7c8d5aa
No related branches found
No related tags found
1 merge request!773feat(audit): don't print None values
Pipeline #29221 failed
......@@ -122,6 +122,11 @@ struct AuditSerializer {
}
impl slog::Serializer for AuditSerializer {
/// Don't print `None` values at all.
fn emit_none(&mut self, _key: slog::Key) -> slog::Result {
Ok(())
}
fn emit_arguments(&mut self, key: slog::Key, val: &std::fmt::Arguments) -> slog::Result {
// TODO: optimize excessive string allocations here and below.
// TODO: make sure we're not trying to overwrite a value here (via assert).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment