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.


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
  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
    TTCCLayout *p_layout = new TTCCLayout();
    p_layout->setName(QLatin1String("My Layout"));
    // Create an appender
    ConsoleAppender *p_appender = new ConsoleAppender(p_layout, ConsoleAppender::STDOUT_TARGET);
    p_appender->setName(QLatin1String("My Appender"));
    // Set appender on root logger
  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!");


Known Problems


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.


SourceForge.net Logo XX February 2009, Martin Heinrich