Skip to content

Commit

Permalink
Use QtLogging Message Pattern to replace MYNAME (#1367)
Browse files Browse the repository at this point in the history
* use qlogging message pattern to replace MYNAME.

* first cut at removal of MYNAME.

* add message type support

and massage some logging with internal newlines.

* introduce DebugLog class to transform printf ...

style character output into lines suitable for logging.

* handle debug printing in garmin_gpi

including removal of POSIX printf arguement reordring

* use DebugLog with lowranceusr

* use DebugLog in dg100

* fix logging in garmin_txt

* use DebugLog in exif

* use logging for validate.

* fix includes

* use DebugLog in igc

* use logging in kml

* use logging in garmin

* use DebugLog in mtk.

* use DebugLog in tpo

* use logging in trackfilter

* use DebugLog for v900

* use DebugLog in skytraq

* use logging with nmea.

* fix dg100, update references, chop extra newlines.

* appease MSVC C2131

* fix garmin_gpi address debug messages.

and direct vecs debug output to debug msg.

* fix comparison with testo -D 9 igc format

* match globalsat sport ws debug messages

* match ws on fatal()

* update references for option->stderr and

no extra newline on fatal.

* ws

* don't send empty string to QDebug.

* drop another empty string from logging.

* cleanup fatal, flush is done in message handler.

* move conditional logging check earlier.

* make member functions static

* fix debug build.

* eliminate some QString<->QByteArray round trips.

* purse QStrings from fatal routines.

Besides an efficiency hit any variadic argument strings passed to these
routines should already be in local8Bit.

* rename logging functions for easier script editing.

thanks clion.

* add macro gbLogCStr for use with our logging.

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.

* change logging back to using QStrings.

QtMessageHandler operates on QStrings.

* manual rename logging routines in windows only files.

* use global gbLog instead of DebugLog instances.

* convert all gb printflike logging to accumulate lines.

* use gbDebug instead of gbLog.  They are equivalent.

* remove unecessary choping.

* fix getLogString, flush fatal log stream.

* terminate gbFatal format strings with a newline.

Since we flush this isn't necessary, but let's be consistent.

* terminate gbWarning format strings.

* switch to our own MessageHandler for legacy logging.

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.

* rename LegacyLog components.

* update fatal.cc includes

* use same stream in waypt_status_disp & termination in waypt_disp_session.

stderr is a text stream which should translate '\n' -> '\r\n' on windows
automatically.

* review catches, mostly in comments or dead code.
  • Loading branch information
tsteven4 authored Nov 7, 2024
1 parent dfadba0 commit e3c01bc
Show file tree
Hide file tree
Showing 113 changed files with 1,774 additions and 1,816 deletions.
23 changes: 11 additions & 12 deletions arcdist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "arcdist.h"

#include <cmath> // for round
#include <cstdio> // for printf, sscanf
#include <cstdio> // for sscanf
#include <tuple> // for tie, tuple

#include <QByteArray> // for QByteArray
Expand All @@ -37,7 +37,6 @@


#if FILTERS_ENABLED
#define MYNAME "Arc filter"

#define BADVAL 999999

Expand Down Expand Up @@ -66,10 +65,10 @@ void ArcDistanceFilter::arcdist_arc_disp_wpt_cb(const Waypoint* arcpt2)
frac = 1.0;
} else {
if (waypointp == nullptr) {
fatal(FatalMsg() << "Internal error. Attempt to project through a waypoint that doesn't exist");
gbFatal(FatalMsg() << "Internal error. Attempt to project through a waypoint that doesn't exist");
}
if (arcpt1 == nullptr) {
fatal(FatalMsg() << "Internal error: Attempt to project waypoint without predecessor");
gbFatal(FatalMsg() << "Internal error: Attempt to project waypoint without predecessor");
}

std::tie(dist, prjpos, frac) = linedistprj(arcpt1->position(),
Expand Down Expand Up @@ -112,7 +111,7 @@ void ArcDistanceFilter::process()
QString line;

gpsbabel::TextStream stream;
stream.open(arcfileopt, QIODevice::ReadOnly, MYNAME);
stream.open(arcfileopt, QIODevice::ReadOnly);

auto* arcpt1 = new Waypoint;
auto* arcpt2 = new Waypoint;
Expand All @@ -134,7 +133,7 @@ void ArcDistanceFilter::process()
int argsfound = sscanf(CSTR(line), "%lf %lf", &arcpt2->latitude, &arcpt2->longitude);

if ((argsfound != 2) && (line.trimmed().size() > 0)) {
warning(MYNAME ": Warning: Arc file contains unusable vertex on line %d.\n", fileline);
gbWarning("Warning: Arc file contains unusable vertex on line %d.\n", fileline);
} else {
Waypoint* arcpttmp = arcpt1;
arcdist_arc_disp_wpt_cb(arcpt2);
Expand Down Expand Up @@ -190,16 +189,16 @@ void ArcDistanceFilter::process()
}
}
if (global_opts.debug_level >= 1) {
warning("Including waypoint %s at dist:%f lat:%f lon:%f\n",
qPrintable(wp->shortname), ed->distance, wp->latitude, wp->longitude);
gbWarning("Including waypoint %s at dist:%f lat:%f lon:%f\n",
gbLogCStr(wp->shortname), ed->distance, wp->latitude, wp->longitude);
}
}
delete ed;
}
}
del_marked_wpts();
if (global_opts.verbose_status > 0) {
printf(MYNAME "-arc: %u waypoint(s) removed.\n", removed);
gbInfo("%u waypoint(s) removed.\n", removed);
}
}

Expand All @@ -208,14 +207,14 @@ void ArcDistanceFilter::init()
if ((!arcfileopt && !rteopt && !trkopt) ||
(arcfileopt && (rteopt || trkopt)) ||
(rteopt && trkopt)) {
fatal(MYNAME ": Incompatible or incomplete option values!\n");
gbFatal("Incompatible or incomplete option values!\n");
}

pos_dist = 0.0;

if (distopt) {
if (parse_distance(distopt, &pos_dist, kMetersPerMile, MYNAME) == 0) {
fatal(MYNAME ": No distance specified with distance option.\n");
if (parse_distance(distopt, &pos_dist, kMetersPerMile) == 0) {
gbFatal("No distance specified with distance option.\n");
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions bend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "grtcirc.h" // for RAD, heading_true_degrees, gcdist, linepart, radtometers, DEG


#define MYNAME "bend"

#if FILTERS_ENABLED

void BendFilter::init()
Expand Down
10 changes: 4 additions & 6 deletions csv_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#include "src/core/logging.h" // for Warning


#define MYNAME "CSV_UTIL"

/*********************************************************************/
/* csv_stringclean() - remove any unwanted characters from string. */
/* returns copy of string. */
Expand Down Expand Up @@ -229,7 +227,7 @@ csv_linesplit(const QString& string, const QString& delimited_by,
}

if (enclosed) {
Warning() << MYNAME":" <<
Warning() <<
"Warning- Unbalanced Field Enclosures" <<
enclosed_in <<
"on line" <<
Expand Down Expand Up @@ -528,7 +526,7 @@ dec_to_human(const char* format, const char* dirs, double val)
case 'x':
case 'X':
if (index>2) {
fatal(MYNAME ": too many format specifiers\n");
gbFatal("too many format specifiers\n");
}
buff += QString::asprintf(subformat, intvals[index]);
index++;
Expand All @@ -539,7 +537,7 @@ dec_to_human(const char* format, const char* dirs, double val)
case 'g':
case 'G':
if (index>2) {
fatal(MYNAME ": too many format specifiers\n");
gbFatal("too many format specifiers\n");
}
buff += QString::asprintf(subformat, dblvals[index]);
index++;
Expand All @@ -548,7 +546,7 @@ dec_to_human(const char* format, const char* dirs, double val)
buff += subformat;
break;
default:
fatal(MYNAME ": invalid format specifier\n");
gbFatal("invalid format specifier\n");
break;

}
Expand Down
27 changes: 17 additions & 10 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "src/core/datetime.h" // for DateTime


#define gbLogCStr(qstr) qUtf8Printable(qstr)
#define CSTR(qstr) ((qstr).toUtf8().constData())
#define CSTRc(qstr) ((qstr).toLatin1().constData())

Expand Down Expand Up @@ -571,7 +572,9 @@ WaypointList::waypt_disp_session(const session_t* se, T cb)
}
}
if (global_opts.verbose_status) {
fprintf(stdout, "\r\n");
// Terminate the progress line from waypt_status_disp.
fprintf(stderr, "\n");
fflush(stderr);
}
}

Expand Down Expand Up @@ -907,17 +910,21 @@ enum ff_cap {
#define FF_CAP_RW_WPT \
{ (ff_cap) (ff_cap_read | ff_cap_write), ff_cap_none, ff_cap_none}

[[noreturn]] void fatal(QDebug& msginstance);
// cppcheck 2.10.3 fails to assign noreturn attribute to fatal if
[[noreturn]] void gbFatal(QDebug& msginstance);
// cppcheck 2.10.3 fails to assign noreturn attribute to gbFatal if
// the noreturn attribute is listed before the gnu::format attribute.
// A PR to resolve this is https://github.com/danmar/cppcheck/pull/4971,
// but cppcheck works if the noreturn attribute follows the gnu::format
// attribute.
// This can have a large effect on codacy issues from cppcheck
// nullPointerRedundantCheck, nullPointerArithmeticRedundantCheck,
// negativeIndex, arrayIndexOutOfBoundsCond.
[[gnu::format(printf, 1, 2)]] [[noreturn]] void fatal(const char* fmt, ...);
[[gnu::format(printf, 1, 2)]] void warning(const char* fmt, ...);
[[gnu::format(printf, 1, 2)]] [[noreturn]] void gbFatal(const char* fmt, ...);
[[gnu::format(printf, 1, 2)]] void gbWarning(const char* fmt, ...);
[[gnu::format(printf, 1, 2)]] void gbInfo(const char* fmt, ...);
[[gnu::format(printf, 1, 2)]] void gbDebug(const char* fmt, ...);

void gbVLegacyLog(QtMsgType type, const char* fmt, va_list args1);

void printposn(double c, bool is_lat);

Expand All @@ -927,7 +934,7 @@ void* xrealloc(void* p, size_t s);
void xfree(const void* mem);
char* xstrdup(const char* s);

FILE* xfopen(const QString& fname, const char* type, const QString& errtxt);
FILE* xfopen(const QString& fname, const char* type);

// Thin wrapper around fopen() that supports Unicode fname on all platforms.
FILE* ufopen(const QString& fname, const char* mode);
Expand Down Expand Up @@ -1028,11 +1035,11 @@ int xstrtoi(const char* str, char** str_end, int base);
int parse_integer(const QString& str, const QString& id, bool* ok = nullptr, QString* end = nullptr, int base = 10);
double parse_double(const QString& str, const QString& id, bool* ok = nullptr, QString* end = nullptr);
int parse_coordinates(const char* str, int datum, grid_type grid,
double* latitude, double* longitude, const char* module);
double* latitude, double* longitude);
int parse_coordinates(const QString& str, int datum, grid_type grid,
double* latitude, double* longitude, const char* module);
int parse_distance(const QString& str, double* val, double scale, const char* module);
int parse_speed(const QString& str, double* val, double scale, const char* module);
double* latitude, double* longitude);
int parse_distance(const QString& str, double* val, double scale);
int parse_speed(const QString& str, double* val, double scale);

/*
* Color helpers.
Expand Down
Loading

0 comments on commit e3c01bc

Please sign in to comment.