Skip to content

Commit a1bc957

Browse files
committed
MB-60861: Replace use LOG_WARNING with LOG_WARNING_CTX
The macros remain as there is still two entries left in mc_time.cc which needs updating (need some think time to figure out how to represent those ;-)) Change-Id: I44368c9bde860868400d10f9af99e40886e5ad9f Reviewed-on: https://review.couchbase.org/c/kv_engine/+/222594 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Paolo Cocchi <paolo.cocchi@couchbase.com>
1 parent 2c94097 commit a1bc957

File tree

10 files changed

+100
-101
lines changed

10 files changed

+100
-101
lines changed

auditd/src/audit.cc

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

363361
bool 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

auditd/src/audit_interface.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ UniqueAuditPtr create_audit_daemon(std::string config_file) {
2828
return std::make_unique<AuditImpl>(std::move(config_file),
2929
cb::net::getHostname());
3030
} catch (std::runtime_error& err) {
31-
LOG_WARNING("{}", err.what());
31+
LOG_WARNING_CTX("Failed to start audit", {"error", err.what()});
3232
} catch (std::bad_alloc&) {
3333
LOG_WARNING_RAW("Failed to start audit: Out of memory");
3434
}

auditd/src/auditfile.cc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ void AuditFile::iterate_old_files(
4545
callback(path);
4646
}
4747
} catch (const std::exception& e) {
48-
LOG_WARNING(
49-
"AuditFile::iterate_old_files(): Exception occurred "
50-
"while inspecting \"{}\": {}",
51-
p.path().generic_string(),
52-
e.what());
48+
LOG_WARNING_CTX(
49+
"AuditFile::iterate_old_files(): Exception occurred",
50+
{"path", p.path().generic_string()},
51+
{"error", e.what()});
5352
}
5453
}
5554
}
@@ -203,9 +202,9 @@ bool AuditFile::open() {
203202
"Audit file",
204203
{"encrypted", file->is_encrypted() ? "encrypted" : "plain"});
205204
} catch (const std::exception& exception) {
206-
LOG_WARNING("Audit: open error on file {}: {}",
207-
open_file_name.generic_string(),
208-
exception.what());
205+
LOG_WARNING_CTX("Audit: Failed to open file",
206+
{"path", open_file_name.generic_string()},
207+
{"error", exception.what()});
209208
return false;
210209
}
211210

@@ -214,9 +213,9 @@ bool AuditFile::open() {
214213
create_symlink(std::filesystem::path{"."} / open_file_name.filename(),
215214
log_directory / current_audit_link_name);
216215
} catch (const std::exception& e) {
217-
LOG_WARNING("Audit: Failed to create {} symbolic link: {}",
218-
current_audit_link_name,
219-
e.what());
216+
LOG_WARNING_CTX("Audit: Failed to create symbolic link",
217+
{"path", current_audit_link_name},
218+
{"error", e.what()});
220219
}
221220

222221
open_time = auditd_time();
@@ -259,8 +258,8 @@ bool AuditFile::write_event_to_disk(const nlohmann::json& output) {
259258
"Audit: memory allocation error for writing audit event to "
260259
"disk");
261260
} catch (const std::exception& exception) {
262-
LOG_WARNING("Audit: Failed to write event to disk: {}",
263-
exception.what());
261+
LOG_WARNING_CTX("Audit: Failed to write event to disk",
262+
{"error", exception.what()});
264263
close_and_rotate_log();
265264
}
266265

@@ -284,9 +283,9 @@ void AuditFile::set_log_directory(const std::string& new_directory) {
284283
// The directory does not exist and we failed to create
285284
// it. This is not a fatal error, but it does mean that the
286285
// node won't be able to do any auditing
287-
LOG_WARNING(R"(Audit: failed to create audit directory "{}": {})",
288-
new_directory,
289-
error.what());
286+
LOG_WARNING_CTX("Audit: failed to create audit directory",
287+
{"path", new_directory},
288+
{"error", error.what()});
290289
}
291290
}
292291

@@ -308,7 +307,8 @@ bool AuditFile::flush() {
308307
try {
309308
file->flush();
310309
} catch (const std::exception& exception) {
311-
LOG_WARNING("Audit: writing to disk error: {}", exception.what());
310+
LOG_WARNING_CTX("Audit: writing to disk failed",
311+
{"error", exception.what()});
312312
close_and_rotate_log();
313313
return false;
314314
}
@@ -322,9 +322,9 @@ void AuditFile::remove_file(const std::filesystem::path& path) {
322322
try {
323323
remove(path);
324324
} catch (const std::exception& exception) {
325-
LOG_WARNING("Audit: Failed to remove \"{}\": {}",
326-
path.generic_string(),
327-
exception.what());
325+
LOG_WARNING_CTX("Audit: Failed to remove file",
326+
{"path", path.generic_string()},
327+
{"error", exception.what()});
328328
}
329329
}
330330
}

daemon/get_authorization_task.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ void GetAuthorizationTask::externalResponse(cb::mcbp::Status statusCode,
5454
}
5555
}
5656
} catch (const std::exception& e) {
57-
LOG_WARNING(
58-
R"({} GetAuthorizationTask::externalResponse() failed. UUID[{}] "{}")",
59-
cookie.getConnectionId(),
60-
cookie.getEventId(),
61-
e.what());
57+
LOG_WARNING_CTX("GetAuthorizationTask::externalResponse() failed",
58+
{"conn_id", cookie.getConnectionId()},
59+
{"event_id", cookie.getEventId()},
60+
{"error", e.what()});
6261
status = cb::sasl::Error::FAIL;
6362
}
6463
}

daemon/mcbp_executors.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,17 +559,19 @@ static void update_user_permissions_executor(Cookie& cookie) {
559559
} catch (const nlohmann::json::exception& error) {
560560
cookie.setErrorContext(error.what());
561561
status = cb::mcbp::Status::Einval;
562-
LOG_WARNING(
563-
R"({}: update_user_permissions_executor: Failed to parse provided JSON: {})",
564-
cookie.getConnectionId(),
565-
error.what());
562+
LOG_WARNING_CTX(
563+
"update_user_permissions_executor: Failed to parse provided "
564+
"JSON",
565+
{"conn_id", cookie.getConnectionId()},
566+
{"error", error.what()});
566567
} catch (const std::runtime_error& error) {
567568
cookie.setErrorContext(error.what());
568569
status = cb::mcbp::Status::Einval;
569-
LOG_WARNING(
570-
R"({}: update_user_permissions_executor: An error occurred while updating user: {})",
571-
cookie.getConnectionId(),
572-
error.what());
570+
LOG_WARNING_CTX(
571+
"update_user_permissions_executor: An error occurred while "
572+
"updating user permissions",
573+
{"conn_id", cookie.getConnectionId()},
574+
{"error", error.what()});
573575
}
574576

575577
cookie.sendResponse(status);

daemon/settings.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ void Settings::reconfigure(const nlohmann::json& json) {
390390
setSlowPrometheusScrapeDuration(
391391
std::chrono::duration<float>(value.get<float>()));
392392
} else {
393-
LOG_WARNING(R"(Unknown key "{}" in config ignored.)", key);
393+
LOG_WARNING_CTX("Ignoring unknown key in config", {"key", key});
394394
}
395395
}
396396
}

engines/ewouldblock_engine/ewouldblock_engine.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,10 +1242,10 @@ cb::engine_errc EWB_Engine::unknown_command(CookieIface& cookie,
12421242
}
12431243

12441244
if (new_mode == nullptr) {
1245-
LOG_WARNING(
1245+
LOG_WARNING_CTX(
12461246
"EWB_Engine::unknown_command(): "
1247-
"Got unexpected mode={} for EWOULDBLOCK_CTL, ",
1248-
(unsigned int)mode);
1247+
"Unexpected mode for EWOULDBLOCK_CTL, ",
1248+
{"mode", (unsigned int)mode});
12491249
response({},
12501250
{},
12511251
{},
@@ -1843,10 +1843,9 @@ cb::engine_errc EWB_Engine::handleBlockMonitorFile(
18431843
}
18441844

18451845
if (!suspendConn(cookie, id)) {
1846-
LOG_WARNING(
1847-
"EWB_Engine::handleBlockMonitorFile(): "
1848-
"Id {} already registered",
1849-
id);
1846+
LOG_WARNING_CTX(
1847+
"EWB_Engine::handleBlockMonitorFile(): Id already registered",
1848+
{"conn_id", id});
18501849
return cb::engine_errc::key_already_exists;
18511850
}
18521851

@@ -1895,10 +1894,10 @@ cb::engine_errc EWB_Engine::handleBlockMonitorFile(
18951894
thread->start();
18961895
threads.lock()->emplace_back(thread.release());
18971896
} catch (std::exception& e) {
1898-
LOG_WARNING(
1897+
LOG_WARNING_CTX(
18991898
"EWB_Engine::handleBlockMonitorFile(): Failed to create "
1900-
"block monitor thread: {}",
1901-
e.what());
1899+
"block monitor thread",
1900+
{"error", e.what()});
19021901
return cb::engine_errc::failed;
19031902
}
19041903

@@ -1925,7 +1924,8 @@ cb::engine_errc EWB_Engine::handleSuspend(CookieIface* cookie,
19251924
*cookie);
19261925
return cb::engine_errc::success;
19271926
}
1928-
LOG_WARNING("EWB_Engine::handleSuspend(): Id {} already registered", id);
1927+
LOG_WARNING_CTX("EWB_Engine::handleSuspend(): Id already registered",
1928+
{"conn_id", id});
19291929
return cb::engine_errc::key_already_exists;
19301930
}
19311931

@@ -1942,10 +1942,10 @@ cb::engine_errc EWB_Engine::handleResume(CookieIface* cookie,
19421942
*cookie);
19431943
return cb::engine_errc::success;
19441944
}
1945-
LOG_WARNING(
1946-
"EWB_Engine::unknown_command(): No connection registered with id "
1947-
"{}",
1948-
id);
1945+
LOG_WARNING_CTX(
1946+
"EWB_Engine::unknown_command(): No connection registered with "
1947+
"requested id",
1948+
{"conn_id", id});
19491949
return cb::engine_errc::invalid_arguments;
19501950
}
19511951

executor/cb3_executorpool.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ TaskQueue* CB3ExecutorPool::_getTaskQueue(const Taskable& t, TaskType qType) {
300300
curNumThreads = threadQ.size();
301301

302302
if (!bucketPriority) {
303-
LOG_WARNING("Trying to schedule task for unregistered bucket {}",
304-
t.getName());
303+
LOG_WARNING_CTX("Trying to schedule task for unregistered bucket",
304+
{"bucket", t.getName()});
305305
return q;
306306
}
307307

@@ -673,8 +673,8 @@ void CB3ExecutorPool::doTaskQStat(Taskable& taskable,
673673
}
674674
}
675675
} catch (std::exception& error) {
676-
LOG_WARNING("CB3ExecutorPool::doTaskQStat: Failed to build stats: {}",
677-
error.what());
676+
LOG_WARNING_CTX("CB3ExecutorPool::doTaskQStat: Failed to build stats",
677+
{"error", error.what()});
678678
}
679679
}
680680

@@ -719,7 +719,8 @@ static void addWorkerStats(const char* prefix,
719719
add_stat,
720720
cookie);
721721
} catch (std::exception& error) {
722-
LOG_WARNING("addWorkerStats: Failed to build stats: {}", error.what());
722+
LOG_WARNING_CTX("addWorkerStats: Failed to build stats",
723+
{"error", error.what()});
723724
}
724725
}
725726

0 commit comments

Comments
 (0)