[Development] (long) thoughts on categorized logging (qLog)

David Faure david.faure at kdab.com
Thu Feb 23 12:48:09 CET 2012


Hi Lincoln,

Thanks for this updated vision for logging. I like this very much.

On Wednesday 22 February 2012 16:37:20 Lincoln Ramsay wrote:
> PART 1: The logging statements.
> qCDebug(PLUGIN) << "Scanning for plugins in" << paths;
> qCWarning(PLUGIN) << "Could not load plugin" << loader->errorString();

Perfect!

> PART 2: Compatibility with qDebug/qWarning
> qDebug() and qWarning() will be re-implemented as categorized logging 
> statements. Both will use the same, hard-coded category. [...]

Very good. Please don't deprecate it though (you're already calling it 
"legacy") ;)

I consider qDebug("foo") and qDebug() << "foo" to be the very useful "throw-
away" debugging, so indeed it should be on by default, and it should not be 
considered deprecated/legacy.

> PART 3: Turning statements on/off.
> However, since there are likley to be many apps that don't care about 
> logging (or may not expose a way to turn on logging in a third party 
> library) there will also be a text-based config file that the user can 
> create. Where should this file be located? Either the app sets the 
> location of this file by calling qSetLoggingConfigFile() or the user 
> sets the QT_LOGGING_CONFIG environment variable (which overrides the 
> app's default). If the config file exists, the C++ API has no effect. 
> QFileWatcher will be used to monitor the config file so that categories 
> can be turned on/off while the program is running by updating the file.

Sounds good, except that I would want something more global than "one file per 
application". When working on a framework or an entire desktop environment, 
one needs to be able to toggle a debug area across all apps. But the 
environment variable could be used for that, so that's a solution.

> PART 4: Formatting.
> 
> There's a %{category} entry that can appear in the format string. This 
> will be in the default format string.

+1

> PART 5: Saving logs to a file.
> 
> As a special case, the user can direct enabled messages to a file. This 
> is done from the config file.
>
> # write output to a file (in the user's home directory)
> logging.output.file = file.txt

I suppose Windows users would expect relative paths to be "in the CWD, which 
is usually the executable's directory"? Not sure.

Looks good.

-- 
David Faure | david.faure at kdab.com | KDE/Qt Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions




More information about the Development mailing list