diff --git a/.gitignore b/.gitignore index 76e0fbe59..7e78e3fb8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ **/*.rej **/target **/.vscode +pkg/logging/Cargo.lock src/agent/src/version.rs src/agent/kata-agent.service src/agent/protocols/src/*.rs diff --git a/pkg/logging/src/lib.rs b/pkg/logging/src/lib.rs index 670852964..65314237c 100644 --- a/pkg/logging/src/lib.rs +++ b/pkg/logging/src/lib.rs @@ -93,9 +93,7 @@ impl HashSerializer { // Take care to only add the first instance of a key. This matters for loggers (but not // Records) since a child loggers have parents and the loggers are serialised child first // meaning the *newest* fields are serialised first. - if !self.fields.contains_key(&key) { - self.fields.insert(key, value); - } + self.fields.entry(key).or_insert(value); } fn remove_field(&mut self, key: &str) {