MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / logQuery

Function logQuery

src/Interpreters/executeQuery.cpp:251–299  ·  view source on GitHub ↗

Log query into text log (not into system table).

Source from the content-addressed store, hash-verified

249
250/// Log query into text log (not into system table).
251static void logQuery(const String & query, ContextPtr context, bool internal, QueryProcessingStage::Enum stage)
252{
253 if (internal)
254 {
255 LOG_DEBUG(getLogger("executeQuery"), "(internal) {} (stage: {})", toOneLineQuery(query), QueryProcessingStage::toString(stage));
256 }
257 else
258 {
259 const auto & client_info = context->getClientInfo();
260
261 const auto & current_query_id = client_info.current_query_id;
262 const auto & initial_query_id = client_info.initial_query_id;
263 const auto & current_user = client_info.current_user;
264
265 String comment = context->getSettingsRef()[Setting::log_comment];
266 size_t max_query_size = context->getSettingsRef()[Setting::max_query_size];
267
268 if (comment.size() > max_query_size)
269 comment.resize(max_query_size);
270
271 if (!comment.empty())
272 comment = fmt::format(" (comment: {})", comment);
273
274 String line_info;
275 if (client_info.script_line_number)
276 line_info = fmt::format(" (query {}, line {})", client_info.script_query_number, client_info.script_line_number);
277
278 String transaction_info;
279 if (auto txn = context->getCurrentTransaction())
280 transaction_info = fmt::format(" (TID: {}, TIDH: {})", txn->tid, txn->tid.getHash());
281
282 LOG_DEBUG(getLogger("executeQuery"), "(from {}{}{}){}{}{} {} (stage: {})",
283 client_info.current_address->toString(),
284 (current_user != "default" ? ", user: " + current_user : ""),
285 (!initial_query_id.empty() && current_query_id != initial_query_id ? ", initial_query_id: " + initial_query_id : std::string()),
286 transaction_info,
287 comment,
288 line_info,
289 toOneLineQuery(query),
290 QueryProcessingStage::toString(stage));
291
292 if (client_info.client_trace_context.trace_id != UUID())
293 {
294 LOG_TRACE(getLogger("executeQuery"),
295 "OpenTelemetry traceparent '{}'",
296 client_info.client_trace_context.composeTraceparentHeader());
297 }
298 }
299}
300
301/// Log exception (with query info) into text log (not into system table).
302static void logException(ContextPtr context, QueryLogElement & elem, bool log_error = true)

Callers 2

executeQueryImplFunction · 0.85
executeQueryFunction · 0.85

Calls 11

toOneLineQueryFunction · 0.85
getCurrentTransactionMethod · 0.80
getLoggerFunction · 0.70
toStringFunction · 0.70
formatFunction · 0.70
sizeMethod · 0.45
resizeMethod · 0.45
emptyMethod · 0.45
getHashMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected