00001 /****************************************************************************** 00002 * 00003 * package: Log4Qt 00004 * file: hierarchy.h 00005 * created: September 2007 00006 * author: Martin Heinrich 00007 * 00008 * 00009 * Copyright 2007 Martin Heinrich 00010 * 00011 * Licensed under the Apache License, Version 2.0 (the "License"); 00012 * you may not use this file except in compliance with the License. 00013 * You may obtain a copy of the License at 00014 * 00015 * http://www.apache.org/licenses/LICENSE-2.0 00016 * 00017 * Unless required by applicable law or agreed to in writing, software 00018 * distributed under the License is distributed on an "AS IS" BASIS, 00019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 * See the License for the specific language governing permissions and 00021 * limitations under the License. 00022 * 00023 ******************************************************************************/ 00024 00025 #ifndef LOG4QT_HIERARCHY_H 00026 #define LOG4QT_HIERARCHY_H 00027 00028 00029 /****************************************************************************** 00030 * Dependencies 00031 ******************************************************************************/ 00032 00033 #include "log4qt/loggerrepository.h" 00034 00035 #include <QtCore/QHash> 00036 #include <QtCore/QReadWriteLock> 00037 00038 00039 /****************************************************************************** 00040 * Declarations 00041 ******************************************************************************/ 00042 00043 namespace Log4Qt 00044 { 00045 00051 class Hierarchy : public LoggerRepository 00052 { 00053 public: 00054 Hierarchy(); 00055 // Hierarchy(const Hierarchy &rOther); // Use compiler default 00056 virtual ~Hierarchy(); 00057 // Hierarchy &operator=(const Hierarchy &rOther); // Use compiler default 00058 00059 public: 00060 virtual bool exists(const QString &rName) const; 00061 virtual Logger *logger(const QString &rName); 00062 virtual QList<Logger *> loggers() const; 00063 // JAVA: virtual Logger *logger(const String &rName, LoggerFactory *pFactory); 00064 virtual Logger *rootLogger() const; 00065 virtual Level threshold() const; 00066 virtual void setThreshold(Level level); 00067 virtual void setThreshold(const QString &rThreshold); 00068 00069 // JAVA: void clear(); 00070 virtual bool isDisabled(Level level); 00071 virtual void resetConfiguration(); 00072 virtual void shutdown(); 00073 00074 // JAVA: virtual void addHierarchyEventListener(HierarchyEventListener *pEventListener); 00075 // JAVA: virtual void emitNoAppenderWarning(Logger *plogger) const; 00076 // JAVA: virtual void fireAddAppenderEvent(Logger *plogger, Appender *pAppender) const; 00077 00078 // JAVA: void addRenderer(const QString &rClass, ObjectRenderer *pObjectRenderer); 00079 // JAVA: QHash<QString, ObjectRenderer *> getRendererMap() const; 00080 // JAVA: setRenderer(const QString &rClass, ObjectRenderer *pObjectRenderer); 00081 00082 protected: 00083 #ifndef QT_NO_DEBUG_STREAM 00084 00093 virtual QDebug debug(QDebug &rdebug) const; 00094 #endif 00095 00096 private: 00097 Logger *createLogger(const QString &rName); 00098 void resetLogger(Logger *pLogger, Level level) const; 00099 00100 private: 00101 mutable QReadWriteLock mObjectGuard; 00102 QHash<QString, Logger*> mLoggers; 00103 volatile bool mHandleQtMessages; 00104 Level mThreshold; 00105 Logger *mpRootLogger; 00106 }; 00107 00108 00109 /************************************************************************** 00110 * Operators, Helper 00111 **************************************************************************/ 00112 00113 00114 /************************************************************************** 00115 * Inline 00116 **************************************************************************/ 00117 00118 inline Logger *Hierarchy::rootLogger() const 00119 { // QReadLocker locker(&mObjectGuard); // Constant for object lifetime 00120 return mpRootLogger; } 00121 00122 inline Level Hierarchy::threshold() const 00123 { // QReadLocker locker(&mObjectGuard); // Level is threadsafe 00124 return mThreshold; } 00125 00126 inline void Hierarchy::setThreshold(Level level) 00127 { // QReadLocker locker(&mObjectGuard); // Level is threadsafe 00128 mThreshold = level; } 00129 00130 inline bool Hierarchy::isDisabled(Level level) 00131 { // QReadLocker locker(&mObjectGuard); // Level is threadsafe 00132 return level < mThreshold; } 00133 00134 00135 } // namespace Log4Qt 00136 00137 00138 // Q_DECLARE_TYPEINFO(Log4Qt::Hierarchy, Q_COMPLEX_TYPE); // Use default 00139 00140 00141 #endif // LOG4QT_HIERARCHY_H