Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use QtLogging Message Pattern to replace MYNAME #1367

Merged
merged 54 commits into from
Nov 7, 2024

Conversation

tsteven4
Copy link
Collaborator

@tsteven4 tsteven4 commented Nov 1, 2024

All the action is in main.cc and fatal.cc. The other 78 files are deletions of MYNAME and descendants. The bulk of the changes were first done by the following script, the remainder by hand.

#!/bin/bash -x
for file in *.cc
do
  sed -i -e 's/MYNAME *"[:-] */"/' $file
  sed -i -e 's/<< *MYNAME *<< *":\? */<< "/' $file
  sed -i -e 's/( *MYNAME *" *:\? */("/' $file
  sed -i -e 's/<< MYNAME "-/<< "/' $file
done

@tsteven4 tsteven4 marked this pull request as draft November 1, 2024 00:25
@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 1, 2024

The bulk edit changed printf statements which don't go through the Qt Logging system. These need adjustment to use the message pattern.

@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 1, 2024

There is another issue with newlines. Traditionally we don't implicitly insert them, e.g. with warning(), but at the same time we expect qDebug() << ... to insert them. gdb in particular expects only explicitly inserted newlines in the DBG printf statements which we want to capture in logging.

and massage some logging with internal newlines.
style character output into lines suitable for logging.
@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 2, 2024

Another issue is the use of printf without a trailing newline. These are sometimes used to accumulate character output which will eventually be terminated with a newline. These newline-less printf statements cannot be logged directly, instead we must transform the character output into lines and log those. DebugLog is a new class to do that, demonstrated in globalsat_sport.

@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 3, 2024

gbser and jeeps logging aren't included.

Besides an efficiency hit any variadic argument strings passed to these
routines should already be in local8Bit.
All but one line was changed by sed (ok, the sed script took
a few tries.)
This allows us to change the encoding passed to our printf style
logging routines in one place.
QtMessageHandler operates on QStrings.
Since we flush this isn't necessary, but let's be consistent.
We don't delay logging until we have a complete line, instead
we output any bits as we go.  We only format the log message if
the last output for the first message or if the last output
character was a newline.
@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 6, 2024

Making allowances for missing/alternate MYNAME content, the log of testo with "-D 9" added to gpsbabel and the auxiliary functions disabled (*compare*, *check) we have only a few mis-compares (out of 1,251,735 lines). These are all related to the alternative representation of the g conversion specifier. The dropped trailing zeros seem to be a bug in QString::vasprintf. The sign of nan may be implementation defined. This seem unimportant to me.

$ diff log4x log7x
4971c4971
< exif: offs 0x000000CA: ifd=2 id=0x829A t=0x0005 c=   1 s=   8 o=0x00000242 +0.00312500(1/320)
---
> exif: offs 0x000000CA: ifd=2 id=0x829A t=0x0005 c=   1 s=   8 o=0x00000242 +0.003125(1/320)
5070c5070
< exif: offs 0x000000E6: ifd=2 id=0x829A t=0x0005 c=   1 s=   8 o=0x00000258 +0.00800000(1/125)
---
> exif: offs 0x000000E6: ifd=2 id=0x829A t=0x0005 c=   1 s=   8 o=0x00000258 +0.008000(1/125)
5138c5138
< exif: offs 0x000000CA: ifd=2 id=0x829A t=0x0005 c=   1 s=   8 o=0x00000242 +0.00312500(1/320)
---
> exif: offs 0x000000CA: ifd=2 id=0x829A t=0x0005 c=   1 s=   8 o=0x00000242 +0.003125(1/320)
5247c5247
< exif: offs 0x000001B4: ifd=2 id=0x9102 t=0x0005 c=   1 s=   8 o=0x0000026C -nan(0/0)
---
> exif: offs 0x000001B4: ifd=2 id=0x9102 t=0x0005 c=   1 s=   8 o=0x0000026C +nan(0/0)
5253c5253
< exif: offs 0x000001FC: ifd=2 id=0x9206 t=0x0005 c=   1 s=   8 o=0x0000029C -nan(0/0)
---
> exif: offs 0x000001FC: ifd=2 id=0x9206 t=0x0005 c=   1 s=   8 o=0x0000029C +nan(0/0)

@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 6, 2024

The Qt Logging system is line based with implied newlines, while our traditional logging is printf based with explicit newlines.

Sometimes we use multiple printf commands to assemble a line of log output.

Another wrinkle is live status like waypt_status_disp with it's '\r' characters and mtk_logger with it's erase wheel '\b' character and mtk_read's Reading status update with '\b's. waypt_status_disp can be exercised with a modified dg100.test, but exercising the above portions of mtk requires a device.

To deal with this I created a LegacyLogMessageHandler that we use with our traditional printf based logging. We use the Qt defaultMessageHandler for qDebug, qInfo, qWarning, ... and our src/core/logging based messages. Our legacy handler only formats a message with qFormatLogMessage (which inserts the "id: ", the replacement for MYNAME) on new log lines and outputs any messages regardless of newline content immediately. The defaultMessageHandler provide by Qt always formats a message with qFormatLogMessage and always uses an implied newline.

@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 6, 2024

Our legacy logger is currently implemented with QString::vasprintf, as is Qt printf style logging. If PIGS_FLY we can switch back to character string conversion. QString::vasprintf expects utf-8 encoded format and character strings arguments, while xvasprintf would want local8Bit encoding. The encoding is switchable be redefining gbLogCStr

@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 6, 2024

The "[id]: " message insertion is set up by setMessagePattern in main. As main runs formats and filters it updates the message pattern.

Copy link
Collaborator

@robertlipe robertlipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! What a slog.

When I first started kicking around the idea of moving to c++ and having formats a s classes, MYNAME was one of the justifications for doign so. I'm happy you sent this to the grave it deserves.

Thanx!

…ion.

stderr is a text stream which should translate '\n' -> '\r\n' on windows
automatically.
@tsteven4
Copy link
Collaborator Author

tsteven4 commented Nov 7, 2024

One thing not converted is printf usage in gbser* or jeeps.

@tsteven4 tsteven4 merged commit e3c01bc into GPSBabel:master Nov 7, 2024
18 checks passed
@tsteven4 tsteven4 deleted the mynamebyebye branch November 7, 2024 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants