dlr-gtlab / gt-logging

Basic C++14 logging library based on QsLog
1 stars 1 forks source link

Resolve "Verbose option for the logging system" - [merged] #92

Closed rainman110 closed 11 months ago

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 20, 2022, 14:59

Merges 29-verbose-option-for-the-logging-system-2 -> master

This MR adds support for logging of verbose message, as

gtError().verbose() << "This verbose error should must appear";

Depending on the verbosity of the logger, the message will either be logged or not. For more information, look at the tests.

@jensschmeink I tested it also against gtlab core, which works as expected. Note, that the GTLabLogging.dll needs to be copied to GTLab's dll directory, otherwise you'll get an error.

Note, i also fixes many cppcheck issues. If you want to review the verbose() related stuff, just look at the first commit.

Closes #29

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 20, 2022, 15:00

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 20, 2022, 15:01

marked this merge request as ready

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 20, 2022, 19:08

@jensschmeink + @marvinoe21 The tests fail here, since the wrong logging library is loaded to LD_LIBRARY_PATH by the rununittests.sh script. It loads the logging lib from devtools instead of using the library that is beeing build.

Any ideas how to fix the in a good way?

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 20, 2022, 19:30

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 20, 2022, 19:40

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 20, 2022, 19:44

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @jensschmeink on Oct 21, 2022, 06:05

I really like the new feature!

rainman110 commented 2 years ago

In GitLab by @jensschmeink on Oct 21, 2022, 06:06

We need to fix the unittests. The changes themselves look good, so I'll approve after the changes to repair the tests.

rainman110 commented 2 years ago

In GitLab by @jensschmeink on Oct 21, 2022, 06:18

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @jensschmeink on Oct 21, 2022, 06:44

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @jensschmeink on Oct 21, 2022, 06:57

approved this merge request

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 07:14

requested review from @mariusalexander

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 07:15

@mariusalexander I'd love to get a review from you since you have done most one the logger recently. :smile:

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 07:56

Commented on src/gt_logstream.h line 23

There is also the space method analog to nospace

    inline LogStream &quote() { return static_cast<LogStream&>(QDebug::quote());}
    inline LogStream &space() { return static_cast<LogStream&>(QDebug::space());}
rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 07:56

Commented on src/gt_logstream.h line 14

what does MEDIUM indicate?

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 08:03

I like the new changes. Nice to have unittests as well! Can you explain how the new verbosity level functions? Say the LogLevel is InfoLevel but I use gtDebug().verbose() << "...". When will this be logged?

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 08:06

@rainman110 Also Im afraid I did an upsi in the last issue/MR. Have a look at QsLogDisableForThisFile.h, I forgot to add the new gtDebugId etc. macros there. Maybe you could fix this for me in this MR?

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 08:13

The general idea is to have to verbosity levels (e.g. similar to -v and -vv). -v would be verbose (MEDIUM) and -vv would be even more verbose (everything).

By default, messages that are marked by .verbose() are not displayed at all.

To create a verbose message with the highest level (i.e. would only appear on -vv), just use

gtError().verbose() << ...
gtErrpr().verbose(gt::EVERYTHING) << ...

to write a log message, that appears already on the medium verbosity, write

gtErrpr().verbose(gt::MEDIUM) << ...

To set the middle -v level, call logger.setVerbosity(gt::MEDIUM);

To set the highes level -vv (i.e. to show really all messages), call logger.setVerbosity(gt::EVERYTHING);

Understood?

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 08:14

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 08:14

Commented on src/gt_logstream.h line 15

Consider renaming this enum as it may clutter the gt namespace. For example you may append a suffix to the enum values (also I'd prefer Camel Case enums :stuck_out_tongue: ):

    SilentLog,
    MediumLog,
    LogEverything // or "VerboseLog"

Or alternatively use an enum class?

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 08:16

I see, thank you! I like this. This will allow for much more convenient logging

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 08:57

added 2 commits

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 08:58

Commented on src/gt_logstream.h line 15

I was thinking about this too. On the other hand, this will make the logging itself much more inconvenient:

gtError().verbose(gt::Verbosity::SilentLog) << "bla"
rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 09:02

Commented on src/gt_logstream.h line 15

Thats true...

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 09:03

Commented on src/gt_logstream.h line 15

SO what to do? Just using camelcase? Or gt::log::silent?

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 09:10

Commented on src/gt_logstream.h line 15

Hmm I both like gt::Silent and gt::log::Silent. The latter is a bit more explicit but also a bit more annoying :joy: How about methods like

gtError().silent() << "blup"      // == .verbose(gt::log::Silent)
gtError().medium() << "bli"      // == .verbose(gt::log::Medium)
gtError().everything() << "blap"  // == .verbose(gt::log::Everything)
// or alternatively for the latter
gtError().verbose() << "blip"     // since default param is gt::log::Everything
rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 09:13

Commented on src/gt_logstream.h line 15

good idea, then lets just use verbose and medium.

What about this gtError().verbose(int level) gtError().verbose() gtError().medium()

Everything would be duplicate to verbose(), so skip this. Silent() does not make any sense, as it will never be printed ;)

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 09:19

Commented on src/gt_logstream.h line 15

Awesome, I like this. My bad haha

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:28

Commented on src/gt_logstream.h line 23

changed this line in version 9 of the diff

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:28

Commented on src/gt_logstream.h line 14

changed this line in version 9 of the diff

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:28

Commented on src/gt_logstream.h line 15

changed this line in version 9 of the diff

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:28

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:29

@mariusalexander I implemented our ideas. Please check

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 10:35

resolved all threads

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 10:42

Commented on src/gt_logstream.h line 18

I dont want to be annoying but I'd prefer camel case enums as they are used most often. I'll may add this to our coding guidelines. On a side note, why did you choose these numbers, to have a spectrum from 0-9? :)

    Silent = 0,
    Medium = 5,
    Everything = 9
rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:46

Commented on src/gt_logstream.h line 18

I dont want to be annoying but I'd prefer camel case enums as they are used most often.

Okay okay :laughing:

why did you choose these numbers, to have a spectrum from 0-9?

To be potentially able to extend it in future without breaking the API (i.e. to have verbosity levels in between) . This is an old trick from QBasic programming, were you had to write the line number at the beginning of each line. You were always using 10, 20, 30, 40 ... in case you need to add a line in between :smirk:

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:47

Commented on src/gt_logstream.h line 18

changed this line in version 10 of the diff

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:47

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 21, 2022, 10:52

Commented on src/gt_logstream.h line 18

image

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 11:00

Commented on src/gt_logstream.h line 18

No way, haha thats funny! Crazy... I like the trick :wink:

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 11:00

resolved all threads

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 21, 2022, 11:08

Commented on src/QsLog.h line 94

One last thing, before I'll approve. One may use the macro gtDebugId("FancyTag") to log a message with a custom id. However wouldnt it just log [ancyTa] or am I missing something? You could for example use the reg exp: ^".*?"$ to filter this out

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 24, 2022, 15:19

Commented on src/QsLog.h line 94

Maybe we should also move the ctor into the .cpp

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 24, 2022, 19:42

Commented on src/QsLog.h line 94

One last thing, before I'll approve. One may use the macro gtDebugId("FancyTag") to log a message with a custom id. However wouldnt it just log [ancyTa] or am I missing something? You could for example use the reg exp: ^".*?"$ to filter this out

Good catch. Indeed gtDebugId("FancyTag") results in [ancyTag].

if we define however GT_MODULE_ID="FancyTag" is will be [FancyTag]. So there is still something wierd.

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 24, 2022, 19:55

Commented on src/QsLog.h line 94

changed this line in version 11 of the diff

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 24, 2022, 19:55

added 1 commit

Compare with previous version

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 24, 2022, 19:55

Commented on src/QsLog.h line 94

This is now fixed!

rainman110 commented 2 years ago

In GitLab by @rainman110 on Oct 24, 2022, 19:58

Commented on src/QsLog.h line 94

This already contains now the changed semantics of GT_MODULE_ID, which now also needs to be a string, as required by the branch, integrating the moduleid into the metadata.

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 25, 2022, 07:23

Commented on src/QsLog.h line 94

Ok awesome if this has been fixed

rainman110 commented 2 years ago

In GitLab by @mariusalexander on Oct 25, 2022, 07:26

resolved all threads