Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-25530

QtLogger: Allow using logging categories without the QT_LOG_CATEGORY macro

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P4: Low
    • None
    • 5.0.0
    • Core: I/O
    • None

    Description

      We need the "unregister on destruction" patch (https://codereview.qt-project.org/#change,23817) before this can be done.

      The basic idea would be to replace uses of QT_LOG_CATEGORY(CAT, "id") with SomeObj CAT("id"). The reason being that apps could more flexibly declare their category objects (including both sharing and scope).

      The macro pretty much just does that now but it has a few bits that make it sub-optimal.
      1) It inserts extra characters into the name of the object.
      2) It puts the object into a namespace.
      3) It uses the static keyword.

      Number 1 works in tandem with the qCDebug macro. However, number 2 means that number 1 shouldn't even be required because there's no other classes to clash with. I suspect Number 2 and 3 may exist to force people to place the macro outside of functions.

      Without static a library could declare some category objects that are stored only once for the whole lib (instead of one copy per .cpp file). It also gives apps/libs more flexible control over the lifetime of the objects.

      The main issue here is that logging is in use already. Any changes need to be source compatible. Binary compatibility can probably be broken now but we need to be careful. Upgrade testing will need to be performed.

      I think the ideal would like something like this:

      // Not allowed in functions
      #define QT_LOG_CATEGORY(cat, id) namespace

      { static QLoggingCategory cat(id); }

      Then document how to use QLoggingCategory directly.

      ie.

      in .h
      extern QLoggingCategory cat;

      in .cpp
      QLoggingCategory cat(id);

      qCDebug and friends would take a reference to a QLoggingCategory object. So in both cases above, you'd have:

      qCDebug(cat)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kkohne Kai Köhne
            lramsay Lincoln Ramsay (closed Nokia identity) (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes