File indexing completed on 2024-04-07 04:36:21

0001 /*
0002  * Copyright (C) 2007 Brad Hards <bradh@frogmouth.net>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public
0015  * License along with this library; if not, write to the Free Software
0016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017  * 02110-1301  USA
0018  *
0019  */
0020 
0021 #include "qca_support.h"
0022 
0023 namespace QCA {
0024 
0025 AbstractLogDevice::AbstractLogDevice(const QString &name, QObject *parent)
0026     : QObject(parent)
0027     , m_name(name)
0028 {
0029 }
0030 
0031 AbstractLogDevice::~AbstractLogDevice()
0032 {
0033 }
0034 
0035 QString AbstractLogDevice::name() const
0036 {
0037     return m_name;
0038 }
0039 
0040 void AbstractLogDevice::logTextMessage(const QString &message, Logger::Severity severity)
0041 {
0042     Q_UNUSED(message);
0043     Q_UNUSED(severity);
0044 }
0045 
0046 void AbstractLogDevice::logBinaryMessage(const QByteArray &blob, Logger::Severity severity)
0047 {
0048     Q_UNUSED(blob);
0049     Q_UNUSED(severity);
0050 }
0051 
0052 Logger::Logger()
0053 {
0054     // d pointer?
0055     m_logLevel = Logger::Notice;
0056 }
0057 
0058 Logger::~Logger()
0059 {
0060     // delete d;
0061 }
0062 
0063 QStringList Logger::currentLogDevices() const
0064 {
0065     return m_loggerNames;
0066 }
0067 
0068 void Logger::registerLogDevice(AbstractLogDevice *logger)
0069 {
0070     m_loggers.append(logger);
0071     m_loggerNames.append(logger->name());
0072 }
0073 
0074 void Logger::unregisterLogDevice(const QString &loggerName)
0075 {
0076     for (int i = 0; i < m_loggers.size(); ++i) {
0077         if (m_loggers[i]->name() == loggerName) {
0078             m_loggers.removeAt(i);
0079             --i; // we backstep, to make sure we check the new entry in this position.
0080         }
0081     }
0082     for (int i = 0; i < m_loggerNames.size(); ++i) {
0083         if (m_loggerNames[i] == loggerName) {
0084             m_loggerNames.removeAt(i);
0085             --i; // we backstep, to make sure we check the new entry in this position.
0086         }
0087     }
0088 }
0089 
0090 void Logger::setLevel(Severity level)
0091 {
0092     m_logLevel = level;
0093 }
0094 
0095 void Logger::logTextMessage(const QString &message, Severity severity)
0096 {
0097     if (severity <= level()) {
0098         for (AbstractLogDevice *logger : qAsConst(m_loggers)) {
0099             logger->logTextMessage(message, severity);
0100         }
0101     }
0102 }
0103 
0104 void Logger::logBinaryMessage(const QByteArray &blob, Severity severity)
0105 {
0106     if (severity <= level()) {
0107         for (AbstractLogDevice *logger : qAsConst(m_loggers)) {
0108             logger->logBinaryMessage(blob, severity);
0109         }
0110     }
0111 }
0112 
0113 }