You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We recommend that message template includes all named properties for easier inspection at viewing time.
19
19
20
20
```rust,ignore
21
-
// DON'T: String formatting causes allocations
21
+
// Bad: String formatting causes allocations
22
22
tracing::info!("file opened: {}", path);
23
23
tracing::info!(format!("file opened: {}", path));
24
24
25
-
// DO: Use message templates with named properties
25
+
// Good: Message templates with named properties
26
26
event!(
27
27
name: "file.open.success",
28
28
Level::INFO,
@@ -31,25 +31,22 @@ event!(
31
31
);
32
32
```
33
33
34
-
> **Note**: Use `{{property}}` syntax in message templates. Double braces preserve the literal text
34
+
> **Note**: Use `{{property}}`the syntax in message templates which preserves the literal text
35
35
> while escaping Rust's format syntax. String formatting is deferred until logs are viewed.
36
-
>
37
-
> This pattern may trigger Clippy's [`literal_string_with_formatting_args`](https://rust-lang.github.io/rust-clippy/stable/index.html#literal_string_with_formatting_args)
38
-
> warning so consider suppressing it for logging.
39
36
40
37
### Name Your Events
41
38
42
39
Use hierarchical dot-notation: `<component>.<operation>.<state>`
Do not log plain sensitive data as this might lead to privacy and security incidents.
91
88
92
89
```rust,ignore
93
-
// DON'T: Log potentially sensitive data
90
+
// Bad: Logs potentially sensitive data
94
91
event!(
95
92
name: "file.operation.started",
96
93
Level::INFO,
@@ -99,7 +96,7 @@ event!(
99
96
"reading file {{file.name}} for user {{user.email}}",
100
97
);
101
98
102
-
// DO: Redact sensitive parts
99
+
// Good: Redact sensitive parts
103
100
event!(
104
101
name: "file.operation.started",
105
102
Level::INFO,
@@ -110,9 +107,7 @@ event!(
110
107
```
111
108
112
109
Sensitive data include user email, file paths revealing user identity, filenames containing secrets or tokens,
113
-
file contents with PII, temporary file paths with session IDs and more.
114
-
115
-
Consider using the [`data_privacy`](https://crates.io/crates/data_privacy) crate for consistent redaction.
110
+
file contents with PII, temporary file paths with session IDs and more. Consider using the [`data_privacy`](https://crates.io/crates/data_privacy) crate for consistent redaction.
0 commit comments