hierarchy.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /******************************************************************************
  2. *
  3. * package: Log4Qt
  4. * file: hierarchy.h
  5. * created: September 2007
  6. * author: Martin Heinrich
  7. *
  8. *
  9. * Copyright 2007 Martin Heinrich
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ******************************************************************************/
  24. #ifndef LOG4QT_HIERARCHY_H
  25. #define LOG4QT_HIERARCHY_H
  26. /******************************************************************************
  27. * Dependencies
  28. ******************************************************************************/
  29. #include "log4qt/loggerrepository.h"
  30. #include <QtCore/QHash>
  31. #include <QtCore/QReadWriteLock>
  32. /******************************************************************************
  33. * Declarations
  34. ******************************************************************************/
  35. namespace Log4Qt
  36. {
  37. /*!
  38. * \brief The class Hierarchy implements a logger repository.
  39. *
  40. * \note All the functions declared in this class are thread-safe.
  41. */
  42. class Hierarchy : public LoggerRepository
  43. {
  44. public:
  45. Hierarchy();
  46. // Hierarchy(const Hierarchy &rOther); // Use compiler default
  47. virtual ~Hierarchy();
  48. // Hierarchy &operator=(const Hierarchy &rOther); // Use compiler default
  49. public:
  50. virtual bool exists(const QString &rName) const;
  51. virtual Logger *logger(const QString &rName);
  52. virtual QList<Logger *> loggers() const;
  53. // JAVA: virtual Logger *logger(const String &rName, LoggerFactory *pFactory);
  54. virtual Logger *rootLogger() const;
  55. virtual Level threshold() const;
  56. virtual void setThreshold(Level level);
  57. virtual void setThreshold(const QString &rThreshold);
  58. // JAVA: void clear();
  59. virtual bool isDisabled(Level level);
  60. virtual void resetConfiguration();
  61. virtual void shutdown();
  62. // JAVA: virtual void addHierarchyEventListener(HierarchyEventListener *pEventListener);
  63. // JAVA: virtual void emitNoAppenderWarning(Logger *plogger) const;
  64. // JAVA: virtual void fireAddAppenderEvent(Logger *plogger, Appender *pAppender) const;
  65. // JAVA: void addRenderer(const QString &rClass, ObjectRenderer *pObjectRenderer);
  66. // JAVA: QHash<QString, ObjectRenderer *> getRendererMap() const;
  67. // JAVA: setRenderer(const QString &rClass, ObjectRenderer *pObjectRenderer);
  68. protected:
  69. #ifndef QT_NO_DEBUG_STREAM
  70. /*!
  71. * Writes all object member variables to the given debug stream \a rDebug and
  72. * returns the stream.
  73. *
  74. * <tt>
  75. * %Hierarchy(loggers:6 threshold:"ALL" root-level:"DEBUG" root-appenders:0)
  76. * </tt>
  77. * \sa QDebug, operator<<(QDebug debug, const LoggerRepository &rLoggerRepository)
  78. */
  79. virtual QDebug debug(QDebug &rdebug) const;
  80. #endif
  81. private:
  82. Logger *createLogger(const QString &rName);
  83. void resetLogger(Logger *pLogger, Level level) const;
  84. private:
  85. mutable QReadWriteLock mObjectGuard;
  86. QHash<QString, Logger*> mLoggers;
  87. volatile bool mHandleQtMessages;
  88. Level mThreshold;
  89. Logger *mpRootLogger;
  90. };
  91. /**************************************************************************
  92. * Operators, Helper
  93. **************************************************************************/
  94. /**************************************************************************
  95. * Inline
  96. **************************************************************************/
  97. inline Logger *Hierarchy::rootLogger() const
  98. { // QReadLocker locker(&mObjectGuard); // Constant for object lifetime
  99. return mpRootLogger; }
  100. inline Level Hierarchy::threshold() const
  101. { // QReadLocker locker(&mObjectGuard); // Level is threadsafe
  102. return mThreshold; }
  103. inline void Hierarchy::setThreshold(Level level)
  104. { // QReadLocker locker(&mObjectGuard); // Level is threadsafe
  105. mThreshold = level; }
  106. inline bool Hierarchy::isDisabled(Level level)
  107. { // QReadLocker locker(&mObjectGuard); // Level is threadsafe
  108. return level < mThreshold; }
  109. } // namespace Log4Qt
  110. // Q_DECLARE_TYPEINFO(Log4Qt::Hierarchy, Q_COMPLEX_TYPE); // Use default
  111. #endif // LOG4QT_HIERARCHY_H