| 1 |
/* |
| 2 |
Copyright (c) 2010 Karl-Heinz Reichel (khreichel at googlemail dot com) |
| 3 |
|
| 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 2.1 |
| 6 |
as published by the Free Software Foundation and appearing in the file |
| 7 |
LICENSE.LGPL included in the packaging of this file. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
*/ |
| 14 |
// Local |
| 15 |
#include "win32/OutputDebugAppender.h" |
| 16 |
|
| 17 |
#include <spdlog/sinks/msvc_sink.h> |
| 18 |
#include <spdlog/spdlog.h> |
| 19 |
|
| 20 |
// STL |
| 21 |
#include <windows.h> |
| 22 |
|
| 23 |
DLOG_CORE_BEGIN_NAMESPACE |
| 24 |
|
| 25 |
/*! |
| 26 |
\class Dtk::Core::OutputDebugAppender |
| 27 |
\inmodule dtkcore |
| 28 |
|
| 29 |
\brief Appender that writes the log records to the Microsoft Debug Log. |
| 30 |
*/ |
| 31 |
|
| 32 |
/*! |
| 33 |
\brief Writes the log record to the windows debug log. |
| 34 |
\reimp |
| 35 |
|
| 36 |
\brief Writes the log record to the windows debug log. |
| 37 |
|
| 38 |
The \a time parameter indicates the time stamp. |
| 39 |
The \a level parameter describes the LogLevel. |
| 40 |
The \a file parameter is the current file name. |
| 41 |
The \a line parameter indicates the number of lines to output. |
| 42 |
The \a func parameter indicates the function name to output. |
| 43 |
The \a category parameter indicates the log category. |
| 44 |
The \a msg parameter indicates the output message. |
| 45 |
|
| 46 |
\sa AbstractStringAppender::format() |
| 47 |
*/ |
| 48 |
void OutputDebugAppender::append(const QDateTime &time, |
| 49 |
Logger::LogLevel level, |
| 50 |
const char *file, |
| 51 |
int line, |
| 52 |
const char *func, |
| 53 |
const QString &category, |
| 54 |
const QString &msg) |
| 55 |
{ |
| 56 |
auto msvclogger = spdlog::get("msvc"); |
| 57 |
if (!msvclogger) |
| 58 |
msvclogger = spdlog::create<spdlog::sinks::msvc_sink_mt>("msvc", true); |
| 59 |
|
| 60 |
Q_ASSERT(msvclogger); |
| 61 |
|
| 62 |
msvclogger->set_level(spdlog::level::level_enum(detailsLevel())); |
| 63 |
const auto &formatted = formattedString(time, level, file, line, func, category, msg); |
| 64 |
msvclogger->log(spdlog::level::level_enum(level), formatted.toStdString()); |
| 65 |
msvclogger->flush(); |
| 66 |
} |
| 67 |
|
| 68 |
DLOG_CORE_END_NAMESPACE |