qca
logger.cpp
Go to the documentation of this file.00001 /* 00002 * Copyright (C) 2007 Brad Hards <bradh@frogmouth.net> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 * 02110-1301 USA 00018 * 00019 */ 00020 00021 #include "qca_support.h" 00022 00023 namespace QCA { 00024 00025 AbstractLogDevice::AbstractLogDevice(const QString &name, QObject *parent) : 00026 QObject( parent ), m_name( name ) 00027 { 00028 } 00029 00030 AbstractLogDevice::~AbstractLogDevice() 00031 {} 00032 00033 QString AbstractLogDevice::name() const 00034 { 00035 return m_name; 00036 } 00037 00038 void AbstractLogDevice::logTextMessage( const QString &message, Logger::Severity severity ) 00039 { 00040 Q_UNUSED( message ); 00041 Q_UNUSED( severity ); 00042 } 00043 00044 void AbstractLogDevice::logBinaryMessage( const QByteArray &blob, Logger::Severity severity ) 00045 { 00046 Q_UNUSED( blob ); 00047 Q_UNUSED( severity ); 00048 } 00049 00050 Logger::Logger() 00051 { 00052 // d pointer? 00053 m_logLevel = Logger::Notice; 00054 } 00055 00056 Logger::~Logger() 00057 { 00058 // delete d; 00059 } 00060 00061 QStringList Logger::currentLogDevices() const 00062 { 00063 return m_loggerNames; 00064 } 00065 00066 void Logger::registerLogDevice(AbstractLogDevice* logger) 00067 { 00068 m_loggers.append( logger ); 00069 m_loggerNames.append( logger->name() ); 00070 } 00071 00072 void Logger::unregisterLogDevice(const QString &loggerName) 00073 { 00074 for ( int i = 0; i < m_loggers.size(); ++i ) 00075 { 00076 if ( m_loggers[i]->name() == loggerName ) 00077 { 00078 m_loggers.removeAt( i ); 00079 --i; // we backstep, to make sure we check the new entry in this position. 00080 } 00081 } 00082 for ( int i = 0; i < m_loggerNames.size(); ++i ) 00083 { 00084 if ( m_loggerNames[i] == loggerName ) 00085 { 00086 m_loggerNames.removeAt( i ); 00087 --i; // we backstep, to make sure we check the new entry in this position. 00088 } 00089 } 00090 } 00091 00092 void Logger::setLevel (Severity level) 00093 { 00094 m_logLevel = level; 00095 } 00096 00097 void Logger::logTextMessage(const QString &message, Severity severity ) 00098 { 00099 if (severity <= level ()) { 00100 for ( int i = 0; i < m_loggers.size(); ++i ) 00101 { 00102 m_loggers[i]->logTextMessage( message, severity ); 00103 } 00104 } 00105 } 00106 00107 void Logger::logBinaryMessage(const QByteArray &blob, Severity severity ) 00108 { 00109 if (severity <= level ()) { 00110 for ( int i = 0; i < m_loggers.size(); ++i ) 00111 { 00112 m_loggers[i]->logBinaryMessage( blob, severity ); 00113 } 00114 } 00115 } 00116 00117 } 00118 00119
KDE 4.4 API Reference