2
* Copyright (C) 2015 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authors: Michi Henning <michi.henning@canonical.com>
19
#include <unity/storage/internal/TraceMessageHandler.h>
37
void trace_message_handler(QtMsgType type, const QMessageLogContext& /*context*/, const QString& msg)
40
using namespace std::chrono;
42
static recursive_mutex mutex;
43
lock_guard<decltype(mutex)> lock(mutex);
45
auto now = system_clock::now();
46
auto sys_time = system_clock::to_time_t(now);
48
localtime_r(&sys_time, &local_time);
49
int msecs = duration_cast<milliseconds>(now.time_since_epoch()).count() % 1000;
53
fprintf(stderr, "%s: ", prefix.c_str());
56
strftime(buf, sizeof(buf), "%T", &local_time);
57
fprintf(stderr, "[%s.%03d]", buf, msecs);
61
fputs(" Warning:", stderr);
64
fputs(" Critical:", stderr);
68
fputs(" Fatal:", stderr);
72
break; // No label for debug messages.
74
fprintf(stderr, " %s\n", msg.toLocal8Bit().constData());
75
if (type == QtFatalMsg)
77
abort(); // LCOV_EXCL_LINE
83
TraceMessageHandler::TraceMessageHandler(string const& prog_name)
86
old_message_handler_ = qInstallMessageHandler(trace_message_handler);
89
TraceMessageHandler::~TraceMessageHandler()
91
qInstallMessageHandler(old_message_handler_);
94
} // namespace internal
95
} // namespace storage