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

Function logException

src/Interpreters/executeQuery.cpp:302–339  ·  view source on GitHub ↗

Log exception (with query info) into text log (not into system table).

Source from the content-addressed store, hash-verified

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)
303{
304 String comment;
305 if (!elem.log_comment.empty())
306 comment = fmt::format(" (comment: {})", elem.log_comment);
307
308 /// Message patterns like "{} (from {}){} (in query: {})" are not really informative,
309 /// so we pass elem.exception_format_string as format string instead.
310 PreformattedMessage message;
311 message.format_string = elem.exception_format_string;
312 message.format_string_args = elem.exception_format_string_args;
313
314 const auto & client_info = context->getClientInfo();
315 String line_info;
316 if (client_info.script_line_number)
317 line_info = fmt::format(" (query {}, line {})", client_info.script_query_number, client_info.script_line_number);
318
319 if (elem.stack_trace.empty() || !log_error)
320 message.text = fmt::format("{} (from {}){}{} (in query: {})", elem.exception,
321 context->getClientInfo().current_address->toString(),
322 comment,
323 line_info,
324 toOneLineQuery(elem.query));
325 else
326 message.text = fmt::format(
327 "{} (from {}){}{} (in query: {}), Stack trace (when copying this message, always include the lines below):\n\n{}",
328 elem.exception,
329 context->getClientInfo().current_address->toString(),
330 comment,
331 line_info,
332 toOneLineQuery(elem.query),
333 elem.stack_trace);
334
335 if (log_error)
336 LOG_ERROR(getLogger("executeQuery"), message);
337 else
338 LOG_INFO(getLogger("executeQuery"), message);
339}
340
341static void
342addPrivilegesInfoToQueryLogElement(QueryLogElement & element, const ContextPtr context_ptr)

Callers 3

exceptionMethod · 0.85
logQueryExceptionFunction · 0.85
logExceptionBeforeStartFunction · 0.85

Calls 5

toOneLineQueryFunction · 0.85
formatFunction · 0.70
getLoggerFunction · 0.70
emptyMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected