# Log4Qt

## Introduction

Log4Qt is a C++ port of the Apache Software Foundation Log4j package using the Trolltech Qt Framework. It is intended to be used by open source and commercial Qt projects.

## Documentation

The documentation describes classes and methods that have been added or changed compared to Log4j. The documentation was generated from the source code using Doxygen. It can be accessed here.

## How to use

To use Log4Qt within your software project include the Log4Qt source into your project

1. Download the package from the SourceForge project page
2. Unpack the Log4Qt package
3. Add the log4qt source to the Qt project file by adding the following line
   `include(<unpackdir>/src/log4qt/log4qt.pri)`
4. Include the Logger class, a layout and an appender class to configure Log4Qt to generate output. The example uses the ConsoleAppender with a TTCCLayout
   `include "log4qt/consoleappender.h"`
   `include "log4qt/logger.h"`
   `include "log4qt/ttcclayout.h"`
5. Configure a logger to generate output. The example uses the root logger
   `// Create a layout`
   `Log4Qt::LogManager::rootLogger();`
   `TTCCLayout *p_layout = new TTCCLayout();`
   `p_layout->setName(QLatin1String("My Layout"));`
   `p_layout->activateOptions();`
   `// Create an appender`
   `ConsoleAppender *p_appender = new ConsoleAppender(p_layout, ConsoleAppender::STDOUT_TARGET);`
   `p_appender->setName(QLatin1String("My Appender"));`
   `p_appender->activateOptions();`
   `// Set appender on root logger`
   `Log4Qt::Logger::rootLogger()->setAppender(p_appender);`
6. Request a logger by either calling Log4Qt::Logger::logger or using LOG4QT_DECLARE_QCLASS_LOGGER
   `// Request a logger and output "Hello World!"`
   `Log4Qt::Logger::logger(QLatin1String("My Logger"))->info("Hello World!");`

## Releases

- 0.3 - 01 March 2009
  Bug fixes, compatibility with VS 2008 and Qt 4.5 RC1
  - Fixed a problem where the pParent parameter of the constructor was not passed on to the QObject constructor (logobject.h)
  - Fixed a problem were OptionConverter::toBoolean would not return the default value, if the conversion fails (optionconverter.cpp)
  - Fixed a compile error on VS 2008 by using Q_UNUSED(&rEvent) instead of Q_UNUSED(rEvent) (varia/denyallfilter.h.h)
  - Fixed VS 2008 unreferenced formal parameter warning by using Q_UNUSED (logmanager.cpp, mdc.cpp, ndc.cpp, propertyconfigurator.cpp, helpers/initialisationhelper.cpp, helpers/patternformatter.cpp)
- 0.2 - 30 January 2009
  Bug fixes and compatibility with Qt 4.4
  - Added a compile time version check for the Qt version (log4qt.h)
  - Replaced usage of q_atomic_increment and q_atomic_decrement with QAtomicInt for compilation with Qt 4.4 (helpers/logobject.h)
  - Replaced usage of q_atomic_test_and_set_ptr with QAtomicPointer for compilation with Qt 4.4 (logger.h, helpers/classlogger.cpp, helpers/classlogger.h, helpers/initialisationhelper.h)
  - Fixed a problem with Qt 4.4 where QReadWriteLock is by default non-recursive (hierarchy.cpp, logger.cpp)
  - Resolved compilation problem with Microsoft Visual Studio 2005 (logmanager.cpp, helpers/datetime.cpp)
- 0.1 - 29 December 2007
  Initial Version

## Known Problems

- The Eclipse CDT console does not display the log output of a correctly when using a ConsoleAppender with a TTCCLayout and relative time format. The millisecond count is stripped from the output.

## License

Log4Qt is licensed under the Apache License Version 2.0.

Log4Qt requires the Qt framework that is available under several licensing options (Qt licensing). The package is intended to be used under the Nokia Corporation Qt GPL Exception.

## Links

- The log4j project
- The logcxx project
- The log4cplus project
- The log4c project
- Doxygen

| XX February 2009, Martin Heinrich