Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Showcase
  4. Logger: simple, convinient and thread safe logger for Qt applications
QtWS25 Last Chance

Logger: simple, convinient and thread safe logger for Qt applications

Scheduled Pinned Locked Moved Showcase
loggingqdebug
43 Posts 14 Posters 62.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cyberbobs
    wrote on last edited by
    #5

    Thanks for your question. To be honest, it was my fault: this features (and comparation to QxtLogger) must have been published here at the starting of this topic. But the hard work of documenting the library in english (it was documented poorly and in russian) haven't left place for any good ideas in my mind :)

    The main point of writing this library was to collect the places of code in addition to logging messages. It was quite useful for our small team and rather big codebase.

    I forgot to say, that Logger also installs itself as the Qt message handler, but it cannot be configured in a way that QxtLogger does (haven't any need for this).

    1 Reply Last reply
    0
    • I Offline
      I Offline
      Immii
      wrote on last edited by
      #6

      Can you please let me know where can I download it, it looks good with your texts and I have never used any logger before for Qt

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #7

        [quote author="Immii" date="1292997872"]Can you please let me know where can I download it, it looks good with your texts and I have never used any logger before for Qt[/quote]
        Look at the gitorious link in the original posting. The code is right there!

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jgoluch
          wrote on last edited by
          #8

          This looks like exactly what my application needs - being still new to Qt, can you provide some instructions for how to build this or where to place the files?

          1 Reply Last reply
          0
          • 0 Offline
            0 Offline
            01amit
            wrote on last edited by
            #9

            The above code explaing how to use ConsoleAppender. I am more interested in learning about how to use FileAppender. If I want use the FileAppender in QPushButton what I need to do.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #10

              Why do you think there is a difference, other than switching out FileAppender for ConsoleAppender and making sure it has a file name?

              And what do you mean by
              [quote author="01amit" date="1330493543"]If I want use the FileAppender in QPushButton what I need to do.[/quote]
              Using FileAppender in QPushButton? Do you mean you want to trigger logging something if you click on some push button?

              1 Reply Last reply
              0
              • 0 Offline
                0 Offline
                01amit
                wrote on last edited by
                #11

                Yes, whenever i click on push button it should write something to text file. How do I change the following code if I want to use FileAppender. I am very new to this. Where do I specify file name.
                @
                int main(int argc, char* argv[])
                {
                QCoreApplication app(argc, argv);

                ConsoleAppender* consoleAppender = new ConsoleAppender();
                consoleAppender->setFormat("[%-7l] <%C> %m\n");
                Logger::registerAppender(consoleAppender);

                LOG_INFO("Starting the application");
                int result = app.exec();

                if (result)
                LOG_WARNING() << "Something went wrong." << "Result code is" << result;

                return result;
                }
                @

                Edit: please use @ tags around your code sections; Andre

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #12

                  Take a look at the header file of FileAppender, especially the constructor. It takes one additional argument...

                  1 Reply Last reply
                  0
                  • 0 Offline
                    0 Offline
                    01amit
                    wrote on last edited by
                    #13

                    Thanks. now I understood how to use file appender and log data into txt file. I want use SQL database instead of txt file how can i do that.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #14

                      Write a new appender that does just that. You can start by subclassing AbstractStringAppender. Instead of outputting to file, you can use Qt's SQL classes to output to a database.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        cyberbobs
                        wrote on last edited by
                        #15

                        Andre, thanks for your answers in this topic :)

                        CuteLogger have been updated about a day ago (thanks goes to Karl-Heinz Reichel). We finally got rid of symlinks in repository, added the Win32 builds support and a qmake file, so currently most of the Qt developers can build it without installing cmake.

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          nomiz
                          wrote on last edited by
                          #16

                          Hi there,

                          I'm starting the logger in main(). When I'm including <Logger.h> in some class of my application the compiler states:

                          error: invalid use of incomplete type ‘struct QDebug’
                          error: forward declaration of ‘struct QDebug’

                          and I still need to incude <QDebug> as well. Is that normal behaviour?

                          Thanks!

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            cyberbobs
                            wrote on last edited by
                            #17

                            Please update to the current version of Logger. As of commit "c7d9a27":https://gitorious.org/cutelogger/cutelogger/commit/c7d9a27110b110298fdf42b417b6e0e246fa96af QDebug header is included into Logger.h.

                            1 Reply Last reply
                            0
                            • N Offline
                              N Offline
                              nomiz
                              wrote on last edited by
                              #18

                              Nice, works!

                              1 Reply Last reply
                              0
                              • 0 Offline
                                0 Offline
                                01amit
                                wrote on last edited by
                                #19

                                How to I destroy this logger object and reinstantiate it without existing the application. Say I have three push buttons (1, 2, 3). I want to instantiate when button 1 is pressed. and use LOG_INFO macro when button 2 is pressed. Flush the data to the file when button 3 is pressed and destroy the object. Re-instantiate the class when button 1 is pressed again without closing the application.
                                In my application we never exit the application it contoneously runs. I am looking for a way to instantiate the class, use log_info, detroy the object and then reinstantiate.

                                1 Reply Last reply
                                0
                                • C Offline
                                  C Offline
                                  cyberbobs
                                  wrote on last edited by
                                  #20

                                  Well, I definitely need to ask a question here: why do you need to manually instantiate and destroy Logger?

                                  This library is created as singleton without any visible initialization by design. Its main object is automatically created on the first Logger::* static function or macro call. As you can see in "Logger.cpp":https://gitorious.org/cutelogger/cutelogger/blobs/master/src/Logger.cpp the object is automatically destroyed after the application have been closed (using the qAddPostRoutine function).

                                  So, once again: why do you want to do manually the thing that is done automatically? :)

                                  1 Reply Last reply
                                  0
                                  • 0 Offline
                                    0 Offline
                                    01amit
                                    wrote on last edited by
                                    #21

                                    I want to desroy the object when the button is clicked not when the application have been closed.

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      aekam
                                      wrote on last edited by
                                      #22

                                      in which version of Qt i can find these files, <Logger.h> and <ConsoleAppender.h> ??? :-?

                                      If you take care of inches, you won't have to worry about miles... :)

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        andre
                                        wrote on last edited by
                                        #23

                                        [quote author="aekam" date="1334749555"]in which version of Qt i can find these files, <Logger.h> and <ConsoleAppender.h> ??? :-?[/quote]
                                        You can't. It's an external project. See the very first post in this topic.

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          maxvanceffer
                                          wrote on last edited by
                                          #24

                                          How about logging size ? I searched in several Qt based logging libs ( QxtLogger, log4qt ..... ) didn't find any functions in it, related to the size of log functionality. So it will be very usefull to see this functionality !

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved