@@ -59,8 +59,8 @@ AuditImpl::~AuditImpl() {
5959 create_audit_event (AUDITD_AUDIT_SHUTTING_DOWN_AUDIT_DAEMON, payload);
6060 put_event (AUDITD_AUDIT_SHUTTING_DOWN_AUDIT_DAEMON, payload);
6161 } catch (const std::exception& exception) {
62- LOG_WARNING (" AuditImpl::~AuditImpl(): Failed to add audit event: {} " ,
63- exception.what ());
62+ LOG_WARNING_CTX (" AuditImpl::~AuditImpl(): Failed to add audit event" ,
63+ { " error " , exception.what ()} );
6464 }
6565
6666 {
@@ -118,40 +118,38 @@ bool AuditImpl::configure() {
118118 file_content = cb::dek::Manager::instance ().load (
119119 cb::dek::Entity::Config, configfile, std::chrono::seconds{5 });
120120 if (file_content.empty ()) {
121- LOG_WARNING (R"( Audit::configure: No data in "{}")" , configfile);
121+ LOG_WARNING_CTX (" Audit::configure: No data in file" ,
122+ {" path" , configfile});
122123 return false ;
123124 }
124125 } catch (const std::exception& exception) {
125- LOG_WARNING ( R"( Audit::configure: Failed to load "{}": {} ) " ,
126- configfile,
127- exception.what ());
126+ LOG_WARNING_CTX ( " Audit::configure: Failed to load" ,
127+ { " path " , configfile} ,
128+ { " error " , exception.what ()} );
128129 return false ;
129130 }
130131
131132 nlohmann::json config_json;
132133 try {
133134 config_json = nlohmann::json::parse (file_content);
134135 } catch (const nlohmann::json::exception&) {
135- LOG_WARNING (
136- R"( Audit::configure: JSON parsing error of "{}" with content: "{}")" ,
137- configfile,
138- cb::UserDataView (file_content));
136+ LOG_WARNING_CTX (" Audit::configure: JSON parsing error" ,
137+ {" path" , configfile},
138+ {" content" , cb::UserDataView (file_content)});
139139 return false ;
140140 }
141141
142142 try {
143143 config = AuditConfig (config_json);
144144 } catch (const nlohmann::json::exception& e) {
145- LOG_WARNING (
146- R"( Audit::configure:: Configuration error in "{}". Error: {}.)"
147- R"( Content: {})" ,
148- cb::UserDataView (configfile),
149- cb::UserDataView (e.what ()),
150- cb::UserDataView (file_content));
145+ LOG_WARNING_CTX (" Audit::configure:: Configuration error" ,
146+ {" path" , cb::UserDataView (configfile)},
147+ {" error" , cb::UserDataView (e.what ())},
148+ {" content" , cb::UserDataView (file_content)});
151149 return false ;
152150 } catch (const std::exception& exception) {
153- LOG_WARNING (" Audit::configure: Initialization failed: {} " ,
154- exception.what ());
151+ LOG_WARNING_CTX (" Audit::configure: Initialization failed" ,
152+ { " error " , exception.what ()} );
155153 return false ;
156154 }
157155
@@ -182,10 +180,10 @@ bool AuditImpl::configure() {
182180 }
183181 } catch (const std::exception& exception) {
184182 dropped_events++;
185- LOG_WARNING (
183+ LOG_WARNING_CTX (
186184 " Audit::configure(): Failed to add audit event for "
187- " audit configure: {} " ,
188- exception.what ());
185+ " audit configure" ,
186+ { " error " , exception.what ()} );
189187 }
190188 }
191189
@@ -284,7 +282,7 @@ bool AuditImpl::put_event(uint32_t event_id, nlohmann::json payload) {
284282 }
285283
286284 dropped_events++;
287- LOG_WARNING (" Audit: Dropping audit event {} " , event_id);
285+ LOG_WARNING_CTX (" Audit: Dropping audit event" , { " id " , event_id} );
288286 return false ;
289287}
290288
@@ -338,12 +336,12 @@ void AuditImpl::consume_events() {
338336 }
339337 }
340338 } catch (const std::exception& e) {
341- LOG_WARNING (
339+ LOG_WARNING_CTX (
342340 " AuditImpl::consume_events(): Got exception while "
343- " processing event: {} ({}): {} " ,
344- event->id ,
345- cb::tagUserData (event->payload .dump ()),
346- e.what ());
341+ " processing event" ,
342+ { " id " , event->id } ,
343+ { " content " , cb::tagUserData (event->payload .dump ())} ,
344+ { " error " , e.what ()} );
347345 dropped_events++;
348346 }
349347 processeventqueue.pop ();
@@ -362,17 +360,17 @@ std::unique_ptr<AuditEventFilter> AuditImpl::createAuditEventFilter() {
362360
363361bool AuditImpl::write_to_audit_trail (const nlohmann::json& json) {
364362 if (!auditfile.ensure_open ()) {
365- LOG_WARNING (" Audit: error opening audit file. Dropping event: {} " ,
366- cb::UserDataView (json.dump ()));
363+ LOG_WARNING_CTX (" Audit: error opening audit file. Dropping event" ,
364+ { " content " , cb::UserDataView (json.dump ())} );
367365 return false ;
368366 }
369367
370368 if (auditfile.write_event_to_disk (json)) {
371369 return true ;
372370 }
373371
374- LOG_WARNING (" Audit: error writing event to disk. Dropping event: {} " ,
375- cb::UserDataView (json.dump ()));
372+ LOG_WARNING_CTX (" Audit: error writing event to disk. Dropping event" ,
373+ { " content " , cb::UserDataView (json.dump ())} );
376374
377375 // If the write_event_to_disk function returns false then it is
378376 // possible the audit file has been closed. Therefore, ensure
0 commit comments