summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/logger/src/ConsoleAppender.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/logger/src/ConsoleAppender.cpp')
-rw-r--r--utils/rbutilqt/logger/src/ConsoleAppender.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/utils/rbutilqt/logger/src/ConsoleAppender.cpp b/utils/rbutilqt/logger/src/ConsoleAppender.cpp
new file mode 100644
index 0000000000..932ffab787
--- /dev/null
+++ b/utils/rbutilqt/logger/src/ConsoleAppender.cpp
@@ -0,0 +1,64 @@
1/*
2 Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail 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 "ConsoleAppender.h"
16
17// STL
18#include <iostream>
19
20
21/**
22 * \class ConsoleAppender
23 *
24 * \brief ConsoleAppender is the simple appender that writes the log records to the std::cerr output stream.
25 *
26 * ConsoleAppender uses "[%{type:-7}] <%{function}> %{message}\n" as a default output format. It is similar to the
27 * AbstractStringAppender but doesn't show a timestamp.
28 *
29 * You can modify ConsoleAppender output format without modifying your code by using \c QT_MESSAGE_PATTERN environment
30 * variable. If you need your application to ignore this environment variable you can call
31 * ConsoleAppender::ignoreEnvironmentPattern(true)
32 */
33
34
35ConsoleAppender::ConsoleAppender()
36 : AbstractStringAppender()
37 , m_ignoreEnvPattern(false)
38{
39 setFormat("[%{type:-7}] <%{function}> %{message}\n");
40}
41
42
43QString ConsoleAppender::format() const
44{
45 const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN"));
46 return (m_ignoreEnvPattern || envPattern.isEmpty()) ? AbstractStringAppender::format() : (envPattern + "\n");
47}
48
49
50void ConsoleAppender::ignoreEnvironmentPattern(bool ignore)
51{
52 m_ignoreEnvPattern = ignore;
53}
54
55
56//! Writes the log record to the std::cerr stream.
57/**
58 * \sa AbstractStringAppender::format()
59 */
60void ConsoleAppender::append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line,
61 const char* function, const QString& category, const QString& message)
62{
63 std::cerr << qPrintable(formattedString(timeStamp, logLevel, file, line, function, category, message));
64}