propertyconfigurator.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /******************************************************************************
  2. *
  3. * package: Logging
  4. * file: propertyconfigurator.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_PROPERTYCONFIGURATOR_H
  25. #define LOG4QT_PROPERTYCONFIGURATOR_H
  26. /******************************************************************************
  27. * Dependencies
  28. ******************************************************************************/
  29. #include <QtCore/QHash>
  30. #include "log4qt/helpers/logobjectptr.h"
  31. #include "log4qt/log4qt.h"
  32. /******************************************************************************
  33. * Declarations
  34. ******************************************************************************/
  35. class QSettings;
  36. namespace Log4Qt
  37. {
  38. class Appender;
  39. class Layout;
  40. class ListAppender;
  41. class Logger;
  42. class Properties;
  43. class LoggerRepository;
  44. /*!
  45. * \brief The class PropertyConfigurator allows the configuration of the
  46. * package from a JAVA properties file.
  47. *
  48. * \note All the functions declared in this class are thread-safe.
  49. */
  50. class PropertyConfigurator
  51. {
  52. public:
  53. PropertyConfigurator();
  54. // virtual ~PropertyConfigurator(); // Use compiler default
  55. private:
  56. PropertyConfigurator(const PropertyConfigurator &rOther); // Not implemented
  57. PropertyConfigurator &operator=(const PropertyConfigurator &rOther); // Not implemented
  58. public:
  59. /*!
  60. * \sa ConfiguratorHelper::configureError()
  61. */
  62. bool doConfigure(const Properties &rProperties,
  63. LoggerRepository *pLoggerRepository = 0);
  64. /*!
  65. * \sa ConfiguratorHelper::configureError()
  66. */
  67. bool doConfigure(const QString &rConfigFileName,
  68. LoggerRepository *pLoggerRepository = 0);
  69. /*!
  70. * Reads the configuration data from the QSettings object
  71. * \a rSettings.
  72. *
  73. * \sa \ref Properties::load(const QSettings &) "Properties::load()",
  74. * ConfiguratorHelper::configureError()
  75. */
  76. bool doConfigure(const QSettings &rSettings,
  77. LoggerRepository *pLoggerRepository = 0);
  78. // JAVA: void doConfigure(const QUrl &rUrl, LoggerRepository *pLoggerRepository);
  79. /*!
  80. * \sa ConfiguratorHelper::configureError()
  81. */
  82. static bool configure(const Properties &rProperties);
  83. /*!
  84. * \sa ConfiguratorHelper::configureError()
  85. */
  86. static bool configure(const QString &rConfigFilename);
  87. /*!
  88. * Reads the configuration data from the QSettings object
  89. * \a rSettings.
  90. *
  91. * \sa \ref doConfigure(const QSettings &, LoggerRepository *) "doConfigure()",
  92. * \ref Properties::load(const QSettings &) "Properties::load()",
  93. * ConfiguratorHelper::configureError()
  94. */
  95. static bool configure(const QSettings &rSettings);
  96. // JAVA: static void configure(const QUrl &rUrl);
  97. /*!
  98. * \sa ConfiguratorHelper::configureError(),
  99. * ConfiguratorHelper::configurationFile()
  100. */
  101. static bool configureAndWatch(const QString &rConfigFilename);
  102. private:
  103. void configureFromFile(const QString &rConfigFileName,
  104. LoggerRepository *pLoggerRepository);
  105. void configureFromProperties(const Properties &rProperties,
  106. LoggerRepository *pLoggerRepository);
  107. void configureFromSettings(const QSettings &rSettings,
  108. LoggerRepository *pLoggerRepository);
  109. void configureGlobalSettings(const Properties &rProperties,
  110. LoggerRepository *pLoggerRepository) const;
  111. void configureNonRootElements(const Properties &rProperties,
  112. LoggerRepository *pLoggerRepository);
  113. void configureRootLogger(const Properties &rProperties,
  114. LoggerRepository *pLoggerRepository);
  115. void parseAdditivityForLogger(const Properties &rProperties,
  116. Logger *pLogger,
  117. const QString &rLog4jName) const;
  118. LogObjectPtr<Appender> parseAppender(const Properties &rProperties,
  119. const QString &rName);
  120. LogObjectPtr<Layout> parseLayout(const Properties &rProperties,
  121. const QString &rAppenderName);
  122. void parseLogger(const Properties &rProperties,
  123. Logger *pLogger,
  124. const QString &rKey,
  125. const QString &rValue);
  126. void setProperties(const Properties &rProperties,
  127. const QString &rPrefix,
  128. const QStringList &rExclusions,
  129. QObject *pObject);
  130. void startCaptureErrors();
  131. bool stopCaptureErrors();
  132. private:
  133. LogObjectPtr<ListAppender> mpConfigureErrors;
  134. QHash< QString, LogObjectPtr<Appender> > mAppenderRegistry;
  135. };
  136. /**************************************************************************
  137. * Operators, Helper
  138. **************************************************************************/
  139. #ifndef QT_NO_DEBUG_STREAM
  140. /*!
  141. * \relates PropertyConfigurator
  142. *
  143. * Writes all object member variables to the given debug stream \a debug
  144. * and returns the stream.
  145. *
  146. * <tt>
  147. * %PropertyConfigurator()
  148. * </tt>
  149. * \sa QDebug
  150. */
  151. QDebug operator<<(QDebug debug,
  152. const PropertyConfigurator &rPropertyConfigurator);
  153. #endif
  154. /**************************************************************************
  155. * Inline
  156. **************************************************************************/
  157. inline PropertyConfigurator::PropertyConfigurator()
  158. {}
  159. } // namspace Logging
  160. // Q_DECLARE_TYPEINFO(Log4Qt::PropertyConfigurator, Q_COMPLEX_TYPE); // Use default
  161. #endif // LOG4QT_PROPERTYCONFIGURATOR_H