Results 1 to 3 of 3

Thread: Using Log4QT

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Using Log4QT

    Hello!
    I'm new to Qt programming,
    I would like to use Log4Qt as log framework.
    I downloaded related source code, I compiled it as qt library in visual studio 2008.
    Now I have a static library .lib to use in my QT project.
    I'm not able to link this lib to new QT project.
    Log4Qt usage instruction doesn't seem to work.
    Someone can tell me te exact steps to use Log4QT?
    There is another way to log in QT?

    Can anyone help me?
    Thank in advance!

  2. #2
    Join Date
    Apr 2010
    Posts
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using Log4QT

    Hi gpuntoni, perhaps is a little bit late for the answer, but I guess would be useful for new readers that stop by this forum. I don't use log4Qt as a library in my Qt projects, I just include the *.pri file that comes in the log4Qt source folder, but I'll explain how I did it in case that will help you.

    1. Download log4Qt from: http://log4qt.sourceforge.net/
    2. In your project add the line: include(/locationOfYourLog4QtFolder/src/log4qt/log4qt.pri). Look at the line 12 of my .pro file:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2010-12-08T08:17:29
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. TARGET = testLog4Qt
    10. TEMPLATE = app
    11.  
    12. include(/locationOfYourLog4QtFolder/src/log4qt/log4qt.pri)
    13.  
    14. SOURCES += main.cpp\
    15. dialog.cpp
    16.  
    17. HEADERS += dialog.h
    To copy to clipboard, switch view to plain text mode 
    That will include in your project all the source files necessary to work with Log4Qt.
    3. Just add your log4Qt code anywhere in your code:
    Qt Code:
    1. #include "log4qt/consoleappender.h"
    2. #include "log4qt/logger.h"
    3. #include "log4qt/ttcclayout.h"
    4. #include "log4qt/logmanager.h"
    5.  
    6. Dialog::Dialog( QWidget *parent ) : QDialog( parent )
    7. {
    8. Log4Qt::LogManager::rootLogger();
    9. Log4Qt::TTCCLayout *p_layout = new Log4Qt::TTCCLayout();
    10.  
    11. p_layout->setName(QLatin1String("My Layout"));
    12. p_layout->activateOptions();
    13. // Create an appender
    14. Log4Qt::ConsoleAppender *p_appender = new Log4Qt::ConsoleAppender(p_layout, Log4Qt::ConsoleAppender::STDOUT_TARGET);
    15. p_appender->setName(QLatin1String("My Appender"));
    16. p_appender->activateOptions();
    17. // Set appender on root logger
    18. Log4Qt::Logger::rootLogger()->addAppender(p_appender);
    19.  
    20. Log4Qt::Logger::logger(QLatin1String("My Logger"))->info("Hello World!");
    21. }
    To copy to clipboard, switch view to plain text mode 
    4. Now compile your project and it's done. You will see in your Applicatin Output (Alt+3):
    Qt Code:
    1. Starting /home/user/Documents/Qt_Projects/testLog4Qt/testLog4Qt-build-desktop/testLog4Qt...
    2. 99 [] INFO My Logger - Hello World!
    3. /home/user/Documents/Qt_Projects/testLog4Qt/testLog4Qt-build-desktop/testLog4Qt exited with code 0
    To copy to clipboard, switch view to plain text mode 

    Note: If you wish you can use the using namespace Log4Qt, but I'm more the kind of guy that use Log4Qt:: or std::, look at: http://www.parashift.com/c++-faq-lit....html#faq-27.5

  3. The following 3 users say thank you to Netheril for this useful post:

    eumel1990 (31st May 2011), Ricardo_arg (6th November 2012), SirDodger (9th February 2011)

  4. #3
    Join Date
    Jan 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Talking Re: Using Log4QT

    Thanks this was exactly what I was looking for.

Similar Threads

  1. loging to multiple files using Log4Qt
    By zhongzhu in forum Qt Programming
    Replies: 0
    Last Post: 17th June 2009, 10:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.