1 | #include "ExtendedLogChannel.h" |
---|---|
2 | |
3 | #include <sys/time.h> |
4 | #include <Common/CurrentThread.h> |
5 | #include <Common/Exception.h> |
6 | #include <common/getThreadNumber.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | namespace ErrorCodes |
12 | { |
13 | extern const int CANNOT_GETTIMEOFDAY; |
14 | } |
15 | |
16 | ExtendedLogMessage ExtendedLogMessage::getFrom(const Poco::Message & base) |
17 | { |
18 | ExtendedLogMessage msg_ext(base); |
19 | |
20 | ::timeval tv; |
21 | if (0 != gettimeofday(&tv, nullptr)) |
22 | DB::throwFromErrno("Cannot gettimeofday", ErrorCodes::CANNOT_GETTIMEOFDAY); |
23 | |
24 | msg_ext.time_seconds = static_cast<UInt32>(tv.tv_sec); |
25 | msg_ext.time_microseconds = static_cast<UInt32>(tv.tv_usec); |
26 | |
27 | if (current_thread) |
28 | { |
29 | auto query_id_ref = CurrentThread::getQueryId(); |
30 | if (query_id_ref.size) |
31 | msg_ext.query_id.assign(query_id_ref.data, query_id_ref.size); |
32 | } |
33 | |
34 | msg_ext.thread_number = getThreadNumber(); |
35 | |
36 | return msg_ext; |
37 | } |
38 | |
39 | } |
40 |