Project

General

Profile

Logging with scopes

Added by Christian Meyer over 1 year ago

Hi there =)

I recently found this nice trick to debug Wt itself and use scopes to filter for the interesting stuff...

Now I kinda wanna have that useful ability to my own code as well...

Currently I am using the Wt::log("something of my interest") to have that shown up, but it would be nice to disable, once its been debugged, but keep it in case for some future edge cases as the codebase evolves.

So how can I use a scope with the Wt::log function?

Would it be enough to pass the "Scope" as string after << operator?
What Format does it need to be in? Are there subscopes possible? As in "Class.function.loop.etc"

Do I need to call LOGGER("Scope"); and successive LOG_DEBUG("Message");?
But looking in the WLogger.h I do not see an ovious way to incorporate this.

I tried Variations of these things listed here. But it did not work for me.

If this is not yet implemented for us, I'd like to add this as a Feature Request

Thank you for Reading

Cheers
Christian


Replies (2)

RE: Logging with scopes - Added by Roel Standaert over 1 year ago

Using scopes with WLogger

Wt::log takes the type of log message, e.g. Wt::log("debug"). Then, the first string appended to the log entry is taken as the scope, e.g.:

Wt::log("debug") << "MyScope" << ": ...";

There's no fixed format for the scope, but you can only filter on it properly if it doesn't contain whitespace since WLogger::configure takes a whitespace-delimited list.

If you configure the logger with * -debug debug:MyScope, then it should log all debug messages for the scope "MyScope", but no other debug messages.

Logging macros (internal to Wt)

The LOGGER and LOG_DEBUG macros are only active when we're building Wt itself, where we have files starting with:

namespace Wt {

LOGGER("WWidget");

RE: Logging with scopes - Added by Christian Meyer over 1 year ago

Thank you!
That Works =)

Just wanted to add, that

  1. Yes, you can add subscopes, BUT
  2. You need to configure WLogger for each scope seperately.

Also Scopes are not limited to debug and can be used to hide specific types with scopes as well

    (1-2/2)