Log exception (with query info) into text log (not into system table).
| 300 | |
| 301 | /// Log exception (with query info) into text log (not into system table). |
| 302 | static 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 | |
| 341 | static void |
| 342 | addPrivilegesInfoToQueryLogElement(QueryLogElement & element, const ContextPtr context_ptr) |
no test coverage detected