2019-06-14 14:00:37 +00:00
|
|
|
#include "ExtendedLogChannel.h"
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
2018-06-15 17:32:35 +00:00
|
|
|
#include <Common/CurrentThread.h>
|
2019-06-14 14:00:37 +00:00
|
|
|
#include <Common/Exception.h>
|
2020-02-02 02:35:47 +00:00
|
|
|
#include <common/getThreadId.h>
|
2018-06-15 17:32:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2018-11-21 20:56:37 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int CANNOT_GETTIMEOFDAY;
|
|
|
|
}
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
ExtendedLogMessage ExtendedLogMessage::getFrom(const Poco::Message & base)
|
|
|
|
{
|
|
|
|
ExtendedLogMessage msg_ext(base);
|
|
|
|
|
|
|
|
::timeval tv;
|
|
|
|
if (0 != gettimeofday(&tv, nullptr))
|
2018-11-21 20:56:37 +00:00
|
|
|
DB::throwFromErrno("Cannot gettimeofday", ErrorCodes::CANNOT_GETTIMEOFDAY);
|
2018-06-15 17:32:35 +00:00
|
|
|
|
|
|
|
msg_ext.time_seconds = static_cast<UInt32>(tv.tv_sec);
|
|
|
|
msg_ext.time_microseconds = static_cast<UInt32>(tv.tv_usec);
|
2019-02-04 15:39:08 +00:00
|
|
|
|
|
|
|
if (current_thread)
|
2019-07-05 14:15:05 +00:00
|
|
|
{
|
|
|
|
auto query_id_ref = CurrentThread::getQueryId();
|
|
|
|
if (query_id_ref.size)
|
|
|
|
msg_ext.query_id.assign(query_id_ref.data, query_id_ref.size);
|
|
|
|
}
|
2019-02-04 15:39:08 +00:00
|
|
|
|
2020-02-02 02:35:47 +00:00
|
|
|
msg_ext.thread_id = getThreadId();
|
2018-06-15 17:32:35 +00:00
|
|
|
|
|
|
|
return msg_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|