1/*
2 * Copyright (C) 2007 Brad Hards <bradh@frogmouth.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
18 *
19 */
20
21#include "qca_support.h"
22
23#include <utility>
24
25namespace QCA {
26
27AbstractLogDevice::AbstractLogDevice(const QString &name, QObject *parent)
28 : QObject(parent)
29 , m_name(name)
30{
31}
32
33AbstractLogDevice::~AbstractLogDevice()
34{
35}
36
37QString AbstractLogDevice::name() const
38{
39 return m_name;
40}
41
42void AbstractLogDevice::logTextMessage(const QString &message, Logger::Severity severity)
43{
44 Q_UNUSED(message);
45 Q_UNUSED(severity);
46}
47
48void AbstractLogDevice::logBinaryMessage(const QByteArray &blob, Logger::Severity severity)
49{
50 Q_UNUSED(blob);
51 Q_UNUSED(severity);
52}
53
54Logger::Logger()
55{
56 // d pointer?
57 m_logLevel = Logger::Notice;
58}
59
60Logger::~Logger()
61{
62 // delete d;
63}
64
65QStringList Logger::currentLogDevices() const
66{
67 return m_loggerNames;
68}
69
70void Logger::registerLogDevice(AbstractLogDevice *logger)
71{
72 m_loggers.append(t: logger);
73 m_loggerNames.append(t: logger->name());
74}
75
76void Logger::unregisterLogDevice(const QString &loggerName)
77{
78 for (int i = 0; i < m_loggers.size(); ++i) {
79 if (m_loggers[i]->name() == loggerName) {
80 m_loggers.removeAt(i);
81 --i; // we backstep, to make sure we check the new entry in this position.
82 }
83 }
84 for (int i = 0; i < m_loggerNames.size(); ++i) {
85 if (m_loggerNames[i] == loggerName) {
86 m_loggerNames.removeAt(i);
87 --i; // we backstep, to make sure we check the new entry in this position.
88 }
89 }
90}
91
92void Logger::setLevel(Severity level)
93{
94 m_logLevel = level;
95}
96
97void Logger::logTextMessage(const QString &message, Severity severity)
98{
99 if (severity <= level()) {
100 for (AbstractLogDevice *logger : std::as_const(t&: m_loggers)) {
101 logger->logTextMessage(message, severity);
102 }
103 }
104}
105
106void Logger::logBinaryMessage(const QByteArray &blob, Severity severity)
107{
108 if (severity <= level()) {
109 for (AbstractLogDevice *logger : std::as_const(t&: m_loggers)) {
110 logger->logBinaryMessage(blob, severity);
111 }
112 }
113}
114
115}
116

source code of qca/src/support/logger.cpp