log4qt.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /******************************************************************************
  2. *
  3. * package: Log4Qt
  4. * file: logging.h
  5. * created: September 2007
  6. * author: Martin Heinrich
  7. *
  8. *
  9. * changes: Sep 2008, Martin Heinrich:
  10. * - Added a compile time version check for the Qt version
  11. * Jan 2009, Martin Heinrich:
  12. * - Updated documentation and version information for version 0.2
  13. * Feb 2009, Martin Heinrich:
  14. * - Updated version information for version 0.3
  15. *
  16. *
  17. * Copyright 2007 - 2009 Martin Heinrich
  18. *
  19. * Licensed under the Apache License, Version 2.0 (the "License");
  20. * you may not use this file except in compliance with the License.
  21. * You may obtain a copy of the License at
  22. *
  23. * http://www.apache.org/licenses/LICENSE-2.0
  24. *
  25. * Unless required by applicable law or agreed to in writing, software
  26. * distributed under the License is distributed on an "AS IS" BASIS,
  27. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28. * See the License for the specific language governing permissions and
  29. * limitations under the License.
  30. *
  31. ******************************************************************************/
  32. #ifndef LOG4QT_H
  33. #define LOG4QT_H
  34. /*!
  35. * \mainpage
  36. *
  37. * %Log4Qt is a C++ port of the Apache Software Foundation Log4j package
  38. * using the Trolltech Qt Framework.
  39. *
  40. * The documentation describes classes and methods that have been added or
  41. * changed compared to Log4j.
  42. *
  43. * The following sections are describing the implementation in more detail:
  44. * - \ref Changes "Differences to Log4j"
  45. * - \ref Ownership "Object ownership"
  46. * - \ref LogLog "Logging within the package"
  47. * - \ref Init "Initialization procedure"
  48. * - \ref Env "Environment Variables"
  49. * - \ref Undocumented "Undocumented functions"
  50. * - \ref Assumptions "Assumptions"
  51. *
  52. * \author Martin Heinrich
  53. * \version 0.3 (January 2009)
  54. *
  55. */
  56. /*!
  57. * \page Changes Differences to Log4j
  58. *
  59. * The following fundamental differences exist between %Log4Qt and Log4j:
  60. *
  61. * - As a JAVA package Log4j does not have to manage object ownership and
  62. * lifetime in the same way then it is required in C++. For details on
  63. * how object ownership is handled see \ref Ownership "Object ownership".
  64. * - The package uses itself for its internal logging similar to Log4j 1.3.
  65. * For details see \ref LogLog "Logging within the package".
  66. * - The configuration using system properties was replaced with a combination
  67. * of environment variables and application settings. For details see
  68. * \ref Env "Environment Variables".
  69. * - Custom levels are not supported.
  70. * - Multiple Logger Repositories are not supported
  71. *
  72. * The following classes have been changed:
  73. *
  74. * - \ref Log4Qt::AppenderSkeleton "AppenderSkeleton"
  75. * - The procedure of checking, if logging is possible, originally used by
  76. * \ref Log4Qt::WriterAppender "WriterAppender" was generalised and is used
  77. * in \ref Log4Qt::AppenderSkeleton "AppenderSkeleton" and derived classes
  78. * (\ref Log4Qt::AppenderSkeleton::checkEntryConditions() "checkEntryConditions()").
  79. * - The \ref Log4Qt::AppenderSkeleton::doAppend() "doAppend()" member function will
  80. * check the entry conditions by calling the sub-class specific
  81. * \ref Log4Qt::AppenderSkeleton::checkEntryConditions() "checkEntryConditions()".
  82. * If successful the sub-class specific
  83. * \ref Log4Qt::AppenderSkeleton::append() "append()" function is called.
  84. *
  85. * - Configurator
  86. * - Configure functions return a boolean indicating, if the configuration
  87. * was successful.
  88. * - Configure errors are accessible over
  89. * \ref Log4Qt::ConfiguratorHelper::configureError()
  90. * "ConfiguratorHelper::configureError()".
  91. * - Watching for configuration file changes is a function performed
  92. * centrally by the \ref Log4Qt::ConfiguratorHelper "ConfiguratorHelper".
  93. * The class provides signals to notify on configuration change and errors.
  94. * - The class \ref Log4Qt::PropertyConfigurator "PropertyConfigurator" was
  95. * extended to be able to read configuration data from a QSettings object.
  96. *
  97. * - \ref Log4Qt::Level "Level"
  98. * - A new value \ref Log4Qt::Level::NULL_INT "Level::NULL_INT" was
  99. * introduced to indicate there is no level set.
  100. *
  101. * - \ref Log4Qt::Logger "Logger"
  102. * - The method \ref Log4Qt::Logger::isEnabledFor() "isEnabledFor()"
  103. * does also take the repository threshold into account.
  104. * - Several overloaded convenience member function are available to log
  105. * messages with arguments of different types.
  106. * - Two macros, \ref Log4Qt::LOG4QT_DECLARE_STATIC_LOGGER "LOG4QT_DECLARE_STATIC_LOGGER"
  107. * and \ref Log4Qt::LOG4QT_DECLARE_QCLASS_LOGGER "LOG4QT_DECLARE_QCLASS_LOGGER",
  108. * allows retrieving and caching of a pointer to a logger object.
  109. *
  110. * - \ref Log4Qt::LogManager "LogManager"
  111. * - A QtMessage handler can be installed via
  112. * \ref Log4Qt::LogManager::setHandleQtMessages() "setHandleQtMessages()",
  113. * to redirect all messages created by calls to qDebug(), qWarning(),
  114. * qCritical() and qFatal() to a logger. The logger is named Qt and can be
  115. * accessed using \ref Log4Qt::LogManager::qtLogger() "qtLogger()".
  116. * - The initialisation procedure is available over a public method
  117. * (\ref Log4Qt::LogManager::startup() "startup()").
  118. * - The LogManager provides access to the logger used internally by the
  119. * package (\ref Log4Qt::LogManager::logLogger() "logLogger()") and to
  120. * its default initialisation procedure
  121. * (\ref Log4Qt::LogManager::configureLogLogger() "configureLogLogger()").
  122. *
  123. * - \ref Log4Qt::WriterAppender "WriterAppender"
  124. * - The class will call \ref Log4Qt::WriterAppender::handleIoErrors()
  125. * "handleIoErrors()" after all I/O operations. Sub-classes should
  126. * re-implement the function to handle errors.
  127. *
  128. * The following classes have been added:
  129. *
  130. * - An additional appender class, \ref Log4Qt::DebugAppender "DebugAppender",
  131. * was added. The class appends logging events to the platform specific debug
  132. * output.
  133. * - Various helper class have been introduced:
  134. * - \ref Log4Qt::ClassLogger "ClassLogger": The class ClassLogger provides
  135. * logging for a QObject derived class.
  136. * - \ref Log4Qt::ConfiguratorHelper "ConfiguratorHelper": The class
  137. * ConfiguratorHelper provides a configuration file watch and last error
  138. * for configurator classes.
  139. * - \ref Log4Qt::DateTime "DateTime": The class DateTime provides extended
  140. * functionality for QDateTime.
  141. * - \ref Log4Qt::LogError "LogError": The class LogError represents an error.
  142. * - \ref Log4Qt::Factory "Factory": The class Factory provides factories
  143. * for Appender, Filter and Layout objects.
  144. * - \ref Log4Qt::InitialisationHelper "InitialisationHelper": The class
  145. * InitialisationHelper performs static initialisation tasks.
  146. * - \ref Log4Qt::LogObject "LogObject": The class LogObject is the common
  147. * base class for many classes in the package.
  148. * - \ref Log4Qt::LogObjectPtr "LogObjectPtr": The class LogObjectPtr
  149. * implements automatic reference counting for LogObject objects.
  150. * - \ref Log4Qt::PatternFormatter "PatternFormatter": The class
  151. * PatternFormatter formats a logging event based on a pattern string.
  152. * - \ref Log4Qt::Properties "Properties": The class Properties implements a
  153. * JAVA property hash.
  154. */
  155. /*!
  156. * \page Ownership Object ownership
  157. *
  158. * In difference to the JAVA Log4j package %Log4Qt must manage ownership and
  159. * lifetime of the objects used. This is non trivial as objects are created
  160. * and used in different ways.
  161. *
  162. * In general an object can be created explicitly for example an application
  163. * may create Loggers, Appenders and Layouts during creation of a QApplication
  164. * object. But they can also be automatically created by the package on
  165. * startup using a \ref Log4Qt::PropertyConfigurator "PropertyConfigurator"
  166. * configuration file. Objects may also be created the one way and then used
  167. * the other. Object may be used by multiple other objects. A Layout for example
  168. * may be used by multiple Appenders. Objects are also created from multiple
  169. * threads. The creation may happen during static initialisation and the
  170. * deletion during static de-initialization.
  171. *
  172. * The parent child model used by QObject cannot be used to handle this. It
  173. * cannot automatically delete an object that is used by multiple others as
  174. * for example an Appender used by multiple Loggers. In addition to this
  175. * QObjects and their children must reside in the same thread. This would
  176. * either mean to impose restriction on how objects can be created or to move
  177. * objects to a specific thread.
  178. *
  179. * To allow an automatic deletion of not required objects the package
  180. * implements reference counting for Appenders, Layouts and Filters. The
  181. * reference counting is implemented in \ref Log4Qt::LogObject "LogObject",
  182. * which is used as a common base class. The reference count can be explicitly
  183. * changed using the methods \ref Log4Qt::LogObject::retain() "retain()" and
  184. * \ref Log4Qt::LogObject::release() "release()". Alternatively an auto pointer
  185. * is available \ref Log4Qt::LogObjectPtr "LogObjectPtr", which is used
  186. * throughout the package.
  187. *
  188. * The reference counting mechanism will test, if an object has a QObject
  189. * parent object set. If a parent is set, the object will not be deleted, if
  190. * the reference count reaches 0. This allows to mix the reference counted
  191. * paradigm with the QObject parent child one.
  192. *
  193. * The following example configures a logger and uses reference counting to
  194. * manage the ownership of objects.
  195. *
  196. * \code
  197. * // Create layout
  198. * TTCCLayout *p_layout = new TTCCLayout();
  199. *
  200. * // Create appender
  201. * ConsoleAppender *p_appender = new ConsoleAppender(p_layout, ConsoleAppender::STDOUT_TARGET);
  202. * p_appender->activateOptions();
  203. *
  204. * // Get logger
  205. * Logger *p_logger = Logger::logger("MyClass");
  206. * p_logger->addAppender(p_appender);
  207. *
  208. * // ...
  209. *
  210. * // Remove appender from Logger
  211. * p_logger->removeAllAppenders(); // p_appender and p_layout are deleted here
  212. * \endcode
  213. *
  214. * The following example configures a logger and uses QObject ownership of
  215. * objects.
  216. *
  217. * \code
  218. * QObject *p_parent = new MyObject;
  219. *
  220. * // Create objects
  221. * ConsoleAppender *p_appender = new ConsoleAppender(p_parent);
  222. * TTCCLayout *p_layout = new TTCCLayout(p_appender);
  223. *
  224. * // Configure appender
  225. * p_appender->setTarget(ConsoleAppender::STDOUT_TARGET);
  226. * p_appender->setLayout(p_layout);
  227. * p_appender->activateOptions();
  228. *
  229. * // Get logger
  230. * Logger *p_logger = Logger::logger("MyClass");
  231. * p_logger->addAppender(p_appender);
  232. *
  233. * // ...
  234. *
  235. * // Remove appender from Logger
  236. * p_logger->removeAllAppenders();
  237. *
  238. * delete p_parent; // p_appender and p_layout are deleted here
  239. * \endcode
  240. *
  241. * The following example shows how to use objects created on the stack.
  242. *
  243. * \code
  244. * {
  245. * // Create layout
  246. * TTCCLayout layout;
  247. * layout.retain();
  248. *
  249. * // Create appender
  250. * ConsoleAppender appender(&layout, ConsoleAppender::STDOUT_TARGET);
  251. * appender.retain();
  252. * appender.activateOptions();
  253. *
  254. * // Get logger
  255. * Logger *p_logger = Logger::logger("MyClass");
  256. * p_logger->addAppender(&appender);
  257. *
  258. * // ...
  259. *
  260. * // Remove appender from Logger
  261. * p_logger->removeAllAppenders(); // Without retain() program crashes here
  262. *
  263. * } // p_appender and p_layout are deleted here
  264. * \endcode
  265. */
  266. /*!
  267. * \page LogLog Logging within the package
  268. *
  269. * The package uses itself for logging similar to Log4j 1.3. This brings much
  270. * more flexibility over logging to stdout, stderr like in Log4j 1.2 using
  271. * logLog. It also enables the program to capture and handle errors raised by
  272. * the package.
  273. *
  274. * Using this approach introduces the issue of recursion. The following example
  275. * explains a situation where this happens. Let's say all logger are configured
  276. * to be additive and only the root logger has an appender set. The appender
  277. * is a \ref Log4Qt::FileAppender "FileAppender". During the logging of an
  278. * event an I/O error occurs. The \ref Log4Qt::FileAppender "FileAppender" logs
  279. * an event by itself using the logger %Log4Qt::FileAppender. The event is
  280. * passed to the root logger, which calls then the \ref Log4Qt::FileAppender
  281. * "FileAppender". This causes another I/O error, which is logged by
  282. * the \ref Log4Qt::FileAppender "FileAppender".
  283. *
  284. * To avoid an endless loop the appender will drop the event on a recursive
  285. * invocation. This check is done by \ref Log4Qt::AppenderSkeleton
  286. * "AppenderSkeleton" in \ref Log4Qt::AppenderSkeleton::doAppend()
  287. * "doAppend()".
  288. *
  289. * The problem only occurs, if a logger, appender, layout or filter log an
  290. * event while an event is appended. Neither the logger class nor any of the
  291. * layout or filter classes log events during appending of an event. Most of
  292. * the appender classes may log errors during appending. Only the
  293. * \ref Log4Qt::ListAppender "ListAppender" and
  294. * \ref Log4Qt::ListAppender "ConsoleAppender" are not logging events.
  295. *
  296. * The default configuration uses two \ref Log4Qt::ListAppender
  297. * "ConsoleAppender", one for stderr and one for stdout. No event will be
  298. * dropped, because no recursive invocations can occur.
  299. */
  300. /*!
  301. * \page Init Initialization procedure
  302. *
  303. * The package is initialised in two stages. The first stage takes place during
  304. * static initialization. The second stage takes place when the
  305. * \ref Log4Qt::LogManager "LogManager" singleton is created.
  306. *
  307. * During static initialisation the \ref Log4Qt::InitialisationHelper
  308. * "InitialisationHelper" singleton is created . On construction it captures
  309. * the program startup time, reads the required values from the system
  310. * environment and registers the package types with the Qt type system.
  311. *
  312. * The \ref Log4Qt::LogManager "LogManager" singleton is created on first use.
  313. * The creation is usually triggered by the request for a \ref Log4Qt::Logger
  314. * "Logger" object. The call to \ref Log4Qt::Logger::logger()
  315. * "Logger::logger()" is passed through to \ref Log4Qt::LogManager::logger()
  316. * "LogManager::logger()". On creation the \ref Log4Qt::LogManager "LogManager"
  317. * creates a \ref Log4Qt::Hierarchy "Hierarchy" object as logger repository.
  318. *
  319. * After the singleton is created the logging of the package is configured to
  320. * its default by a call to \ref Log4Qt::LogManager::configureLogLogger()
  321. * "LogManager::configureLogLogger()". The logger
  322. * \ref Log4Qt::LogManager::logLogger() "logLogger()" is configured to be not
  323. * additive. Messages with the level \ref Log4Qt::Level::ERROR_INT
  324. * "Level::ERROR_INT" and \ref Log4Qt::Level::FATAL_INT "Level::FATAL_INT" are
  325. * written to \c stderr using a ConsoleAppender. The remaining messages are
  326. * written to \c stdout using a second ConsoleAppender. The level is read from
  327. * the system environment or application settings using
  328. * \ref Log4Qt::InitialisationHelper::setting()
  329. * "InitialisationHelper::setting()" with the key \c Debug. If a level value
  330. * is found, but it is not a valid Level string,
  331. * \ref Log4Qt::Level::DEBUG_INT "Level::DEBUG_INT" is used. If no level string
  332. * is found \ref Log4Qt::Level::ERROR_INT "Level::ERROR_INT" is used.
  333. *
  334. * Once the logging is configured the package is initialised by a call to
  335. * \ref Log4Qt::LogManager::startup() "LogManager::startup()". The function
  336. * will test for the setting \c DefaultInitOverride in the system environment
  337. * and application settings using \ref Log4Qt::InitialisationHelper::setting()
  338. * "InitialisationHelper::setting()". If the value is present and set to
  339. * anything else then \c false, the initialisation is aborted.<br>
  340. * The system environment and application settings are tested for the setting
  341. * \c Configuration. If it is found and it is a valid path to a file, the
  342. * package is configured with the file using
  343. * \ref Log4Qt::PropertyConfigurator::doConfigure(const QString &, LoggerRepository *)
  344. * "PropertyConfigurator::doConfigure()". If the setting \c Configuration is
  345. * not available and a QCoreApplication object is present, the application
  346. * settings are tested for a group \c Log4Qt/Properties. If the group exists,
  347. * the package is configured with the setting using the
  348. * \ref Log4Qt::PropertyConfigurator::doConfigure(const QSettings &r, LoggerRepository *)
  349. * "PropertyConfiguratordoConfigure()". If neither a configuration file nor
  350. * configuration settings could be found, the current working directory is
  351. * searched for the file \c "log4qt.properties". If it is found, the package
  352. * is configured with the file using
  353. * \ref Log4Qt::PropertyConfigurator::doConfigure(const QString &, LoggerRepository *)
  354. * "PropertyConfigurator::doConfigure()".
  355. *
  356. * The following example shows how to use application settings to initialise the
  357. * package.
  358. *
  359. * \code
  360. * # file: myapplication.h
  361. *
  362. * #include qapplication.h
  363. *
  364. * class MyApplication : public QApplication
  365. * {
  366. * Q_OBJECT
  367. *
  368. * public:
  369. * MyApplication();
  370. * ~MyApplication();
  371. * void setupLog4Qt();
  372. * }
  373. * \endcode
  374. * \code
  375. * # file: myapplication.cpp
  376. *
  377. * #include myapplication.h
  378. *
  379. * MyApplication::MyApplication(
  380. * {
  381. * // Set Application data to allow Log4Qt initialisation to read the
  382. * // correct values
  383. * setApplicationName("MyApplication");
  384. * setOrganisationName("MyOrganisation");
  385. * setOrganizationDomain("www.myorganisation.com");
  386. *
  387. * // Log first message, which initialises Log4Qt
  388. * Log4Qt::Logger::logger("MyApplication")->info("Hello World");
  389. * }
  390. *
  391. * MyApplication::~MyApplication()
  392. * {
  393. * }
  394. *
  395. * void MyApplication::setupLog4Qt()
  396. * {
  397. * QSettings s;
  398. *
  399. * // Set logging level for Log4Qt to TRACE
  400. * s.beginGroup("Log4Qt");
  401. * s.setValue("Debug", "TRACE");
  402. *
  403. * // Configure logging to log to the file C:/myapp.log using the level TRACE
  404. * s.beginGroup("Properties");
  405. * s.setValue("log4j.appender.A1", "org.apache.log4j.FileAppender");
  406. * s.setValue("log4j.appender.A1.file", "C:/myapp.log");
  407. * s.setValue("log4j.appender.A1.layout", "org.apache.log4j.TTCCLayout");
  408. * s.setValue("log4j.appender.A1.layout.DateFormat", "ISO8601");
  409. * s.setValue("log4j.rootLogger", "TRACE, A1");
  410. *
  411. * // Settings will become active on next application startup
  412. * }
  413. * \endcode
  414. */
  415. /*!
  416. * \page Env Environment Variables
  417. *
  418. * The package uses environment variables to control the initialization
  419. * procedure. The environment variables replace the system property entries
  420. * used by Log4j.
  421. *
  422. * For compability reasons the Log4j entry is recognised. Alternatively a
  423. * environment variable style Log4Qt form can be used. The following entries
  424. * are used:
  425. *
  426. * - LOG4QT_DEBUG<br>
  427. * The variable controls the \ref Log4Qt::Level "Level" value for the
  428. * logger \ref Log4Qt::LogManager::logLogger() "LogManager::logLogger()".
  429. * If the value is a valid \ref Log4Qt::Level "Level" string, the level for
  430. * the is set to the level. If the value is not a valid
  431. * \ref Log4Qt::Level "Level" string, \ref Log4Qt::Level::DEBUG_INT
  432. * "DEBUG_INT" is used. Otherwise \ref Log4Qt::Level::ERROR_INT "ERROR_INT"
  433. * is used.
  434. * - \ref Log4Qt::LogManager::configureLogLogger()
  435. * "LogManager::configureLogLogger()"
  436. *
  437. * - LOG4QT_DEFAULTINITOVERRIDE<br>
  438. * The variable controls the \ref Init "initialization procedure" performed
  439. * by the \ref Log4Qt::LogManager "LogManager" on startup. If it is set to
  440. * any other value then \c false the \ref Init "initialization procedure"
  441. * is skipped.
  442. * - \ref Log4Qt::LogManager::startup() "LogManager::startup()"
  443. *
  444. * - LOG4QT_CONFIGURATION<br>
  445. * The variable specifies the configuration file used for initialising the
  446. * package.
  447. * - \ref Log4Qt::LogManager::startup() "LogManager::startup()"
  448. *
  449. * - LOG4QT_CONFIGURATORCLASS<br>
  450. * The variable specifies the configurator class used for initialising the
  451. * package.
  452. *
  453. * Environment variables are read during static initialisation on creation of
  454. * the \ref Log4Qt::InitialisationHelper "InitialisationHelper". They can be
  455. * accessed by calling \ref Log4Qt::InitialisationHelper::environmentSettings()
  456. * "InitialisationHelper::environmentSettings()".
  457. *
  458. * All settings can also be made in the application settings under the group
  459. * \c %Log4Qt. For example the environment variable \c LOG4QT_DEBUG is
  460. * equivalent to the setting \c Log4Qt/Debug. If an environment variable is
  461. * set it takes precedence over the application setting. Settings are only
  462. * used, if an QApplication object is available, when the
  463. * \ref Log4Qt::LogManager "LogManager" is
  464. * initialised (see \ref Log4Qt::InitialisationHelper::setting()
  465. * "InitialisationHelper::setting()" for details).
  466. */
  467. /*!
  468. * \page Undocumented Undocumented functions
  469. *
  470. * In general it was tried to avoid the usage of undocumented features of Qt.
  471. * Nice to have features like for example Q_DECLARE_PRIVATE are not used. Only
  472. * features that would have been resulted in re-coding the same functionality
  473. * are used.
  474. *
  475. * - QT_WA: The macro is used to call Windows A/W functions
  476. * - \ref Log4Qt::DebugAppender "DebugAppender"
  477. * - QBasicAtomicPointer: The class is used instead of QAtomicPointer, because
  478. * it allows the initialisation as plain old data type.
  479. * - \ref Log4Qt::LOG4QT_GLOBAL_STATIC "LOG4QT_GLOBAL_STATIC"
  480. * - \ref Log4Qt::LOG4QT_IMPLEMENT_INSTANCE "LOG4QT_IMPLEMENT_INSTANCE"
  481. * - \ref Log4Qt::LOG4QT_DECLARE_STATIC_LOGGER "LOG4QT_DECLARE_STATIC_LOGGER"
  482. * - Q_BASIC_ATOMIC_INITIALIZER: The macro is used to initialise QAtomicPointer
  483. * objects as plain old data type.
  484. * - \ref Log4Qt::LOG4QT_GLOBAL_STATIC "LOG4QT_GLOBAL_STATIC"
  485. * - \ref Log4Qt::LOG4QT_IMPLEMENT_INSTANCE "LOG4QT_IMPLEMENT_INSTANCE"
  486. * - \ref Log4Qt::LOG4QT_DECLARE_STATIC_LOGGER "LOG4QT_DECLARE_STATIC_LOGGER"
  487. */
  488. /*!
  489. * \page Assumptions Assumptions
  490. *
  491. * The following assumptions are used throughout the package:
  492. *
  493. * - Reading / writing of bool or int is thread-safe, if declared volatile
  494. * - \ref Log4Qt::ListAppender "ListAppender"
  495. * - \ref Log4Qt::AppenderSkeleton "AppenderSkeleton"
  496. * - \ref Log4Qt::ConsoleAppender "ConsoleAppender"
  497. * - \ref Log4Qt::FileAppender "FileAppender"
  498. * - \ref Log4Qt::Hierarchy "Hierarchy"
  499. * - \ref Log4Qt::Level "Level"
  500. * - \ref Log4Qt::Logger "Logger"
  501. * - \ref Log4Qt::WriterAppender "WriterAppender"
  502. * - \ref Log4Qt::Layout::format() "Layout::format()" is implemented reentrant
  503. * in all sub-classes.
  504. * - \ref Log4Qt::AppenderSkeleton "AppenderSkeleton"
  505. * - Being able to use singleton objects during static de-initialization without
  506. * order issues is more valuable then their destruction.
  507. * - \ref Log4Qt::LogManager "LogManager"
  508. * - \ref Log4Qt::LOG4QT_GLOBAL_STATIC "LOG4QT_GLOBAL_STATIC"
  509. * - \ref Log4Qt::LOG4QT_IMPLEMENT_INSTANCE "LOG4QT_IMPLEMENT_INSTANCE"
  510. */
  511. /******************************************************************************
  512. * Dependencies
  513. ******************************************************************************/
  514. #include <QtCore/qglobal.h>
  515. #if QT_VERSION < QT_VERSION_CHECK(4, 3, 0)
  516. # error "Log4Qt requires Qt version 4.3.0 or higher"
  517. #endif
  518. /******************************************************************************
  519. * Declarations
  520. ******************************************************************************/
  521. /*!
  522. * \brief The namespace %Log4Qt encloses all parts of the package.
  523. */
  524. namespace Log4Qt
  525. {
  526. /*!
  527. * This macro expands a numeric value of the form 0xMMmmPP (MM = major,
  528. * mm = minor, PP = patch) that specifies Log4Qt's version number.
  529. * This is the version against which the application is compiled.
  530. *
  531. * \sa \ref Log4Qt::LOG4QT_VERSION_STR "LOG4QT_VERSION_STR",
  532. * \ref Log4Qt::LogManager::version() "LogManager::version()"
  533. */
  534. #define LOG4QT_VERSION 0x000200
  535. /*!
  536. * The macro expands to a string that specifies the Log4Qt's version
  537. * number. This is the version against which the application is compiled.
  538. *
  539. * \sa \ref Log4Qt::LOG4QT_VERSION "LOG4QT_VERSION",
  540. * \ref Log4Qt::LogManager::version() "LogManager::version()"
  541. */
  542. #define LOG4QT_VERSION_STR "0.3.0"
  543. enum ErrorCode
  544. {
  545. OK = 0,
  546. // AppenderSkeleton, FileAppender, WriterAppender
  547. APPENDER_ACTIVATE_MISSING_LAYOUT_ERROR,
  548. APPENDER_ACTIVATE_MISSING_WRITER_ERROR,
  549. APPENDER_ACTIVATE_MISSING_FILE_ERROR,
  550. APPENDER_CLOSED_ERROR,
  551. APPENDER_INVALID_PATTERN_ERROR,
  552. APPENDER_NO_OPEN_FILE_ERROR,
  553. APPENDER_NOT_ACTIVATED_ERROR,
  554. APPENDER_OPENING_FILE_ERROR,
  555. APPENDER_RENAMING_FILE_ERROR,
  556. APPENDER_REMOVE_FILE_ERROR,
  557. APPENDER_USE_INVALID_PATTERN_ERROR,
  558. APPENDER_USE_MISSING_LAYOUT_ERROR,
  559. APPENDER_USE_MISSING_WRITER_ERROR,
  560. APPENDER_WRITING_FILE_ERROR,
  561. // Level
  562. LEVEL_INVALID_LEVEL_STRING,
  563. // Layouts, PatternFormatter
  564. LAYOUT_EXPECTED_DIGIT_ERROR,
  565. LAYOUT_OPTION_IS_NOT_INTEGER_ERROR,
  566. LAYOUT_INTEGER_IS_NOT_POSITIVE_ERROR,
  567. // Logger
  568. LOGGER_INVALID_LEVEL_FOR_ROOT,
  569. // PropertyConfigurator, OptionHandler
  570. CONFIGURATOR_OPENING_FILE_ERROR,
  571. CONFIGURATOR_READING_FILE_ERROR,
  572. CONFIGURATOR_INVALID_SUBSTITUTION_ERROR,
  573. CONFIGURATOR_INVALID_OPTION_ERROR,
  574. CONFIGURATOR_MISSING_APPENDER_ERROR,
  575. CONFIGURATOR_UNKNOWN_APPENDER_CLASS_ERROR,
  576. CONFIGURATOR_MISSING_LAYOUT_ERROR,
  577. CONFIGURATOR_UNKNOWN_LAYOUT_CLASS_ERROR,
  578. CONFIGURATOR_PROPERTY_ERROR,
  579. CONFIGURATOR_UNKNOWN_TYPE_ERROR
  580. };
  581. /******************************************************************************
  582. * Operators, Helpers
  583. ******************************************************************************/
  584. /******************************************************************************
  585. * Inline
  586. ******************************************************************************/
  587. } // namespace Log4Qt
  588. #endif // LOG4QT_H