Skip to content

Commit

Permalink
[TASK] Simplify logging to stdout (dev)
Browse files Browse the repository at this point in the history
It was a bit cumbersome to quickly print Qt container types to stdout.
Now we can just use qCritical() << ... . It ends up in the log and on
stdout.

Also qDebug() and friends bring in file, line number and function
signature now (and that is enabled for release builds, too).
In places where we want to customize that we use QMessageLogger (see
Airac.cpp for example).
  • Loading branch information
jonaseberle committed Jun 13, 2023
1 parent ca69901 commit 04fbd00
Show file tree
Hide file tree
Showing 28 changed files with 182 additions and 223 deletions.
1 change: 1 addition & 0 deletions QuteScoop.pro
Expand Up @@ -23,6 +23,7 @@ CONFIG += c++2a
TEMPLATE = app
CONFIG *= qt

DEFINES += QT_MESSAGELOGCONTEXT
CONFIG *= warn_on
TARGET = QuteScoop

Expand Down
21 changes: 13 additions & 8 deletions src/Airac.cpp
Expand Up @@ -38,7 +38,7 @@ Airac::~Airac() {
}

void Airac::load() {
qDebug() << "Airac::load()" << Settings::navdataDirectory();
qDebug() << Settings::navdataDirectory();
GuiMessages::status("Loading navigation database...", "airacload");
if (Settings::useNavdata()) {
readFixes(Settings::navdataDirectory());
Expand All @@ -61,7 +61,6 @@ void Airac::load() {

GuiMessages::remove("airacload");
emit loaded();
qDebug() << "Airac::load() -- finished";
}

void Airac::readFixes(const QString& directory) {
Expand Down Expand Up @@ -167,8 +166,10 @@ void Airac::readAirways(const QString& directory) {
}

bool ok;
unsigned int count = 0;
int segments = 0;
while (!fr.atEnd()) {
++count;
QString line = fr.nextLine().trimmed();
// file format:
// EXOLU VA 11 TAXUN VA 11 N 2 75 460 B342-N519-W14
Expand All @@ -185,33 +186,38 @@ void Airac::readAirways(const QString& directory) {

QStringList list = line.split(' ', Qt::SkipEmptyParts);
if (list.size() != 11) {
qCritical() << "Airac::readAirways() not exactly 11 fields:" << list;
QMessageLogger(file.toLocal8Bit(), count, QT_MESSAGELOG_FUNC).critical()
<< "not exactly 11 fields:" << list;
continue;
}

QString id = list[0];
QString regionCode = list[1];
int fixType = list[2].toInt(&ok);
if (!ok) {
qCritical() << "Airac::readAirways() unable to parse fix type (int):" << list;
QMessageLogger(file.toLocal8Bit(), count, QT_MESSAGELOG_FUNC).critical()
<< "unable to parse fix type (int):" << list;
continue;
}
Waypoint* start = waypoint(id, regionCode, fixType);
if (start == 0) {
qCritical() << "Airac::readAirways() unable to find start waypoint:" << QStringList{ id, regionCode, QString::number(fixType) } << list;
QMessageLogger(file.toLocal8Bit(), count, QT_MESSAGELOG_FUNC).critical()
<< "unable to find start waypoint:" << QStringList{ id, regionCode, QString::number(fixType) } << list;
continue;
}

id = list[3];
regionCode = list[4];
fixType = list[5].toInt(&ok);
if (!ok) {
qCritical() << "Airac::readAirways() unable to parse fix type (int):" << list;
QMessageLogger(file.toLocal8Bit(), count, QT_MESSAGELOG_FUNC).critical()
<< "unable to parse fix type (int):" << list;
continue;
}
Waypoint* end = waypoint(id, regionCode, fixType);
if (end == 0) {
qCritical() << "Airac::readAirways() unable to find end waypoint:" << QStringList{ id, regionCode, QString::number(fixType) } << list;
QMessageLogger(file.toLocal8Bit(), count, QT_MESSAGELOG_FUNC).critical()
<< "unable to find start waypoint:" << QStringList{ id, regionCode, QString::number(fixType) } << list;
continue;
}

Expand Down Expand Up @@ -419,7 +425,6 @@ void Airac::addAirwaySegment(Waypoint* from, Waypoint* to, const QString& name)
* Unknown fixes and/or airways will be ignored.
**/
QList<Waypoint*> Airac::resolveFlightplan(QStringList plan, double lat, double lon) {
//qDebug() << "Airac::resolveFlightPlan()" << plan;
QList<Waypoint*> result;
Waypoint* currPoint = 0;
Airway* awy = 0;
Expand Down
13 changes: 4 additions & 9 deletions src/Airport.cpp
Expand Up @@ -88,10 +88,8 @@ Airport::Airport(const QStringList& list, unsigned int debugLineNumber)
resetWhazzupStatus();

if (list.size() != 6) {
auto msg = QString("While processing line #%1 '%2' from data/airports.dat: Found %3 fields, expected exactly 6.")
.arg(debugLineNumber).arg(list.join(':')).arg(list.size());
qCritical() << "Airport::Airport()" << msg;
QTextStream(stdout) << "CRITICAL: " << msg << Qt::endl;
QMessageLogger("airports.dat", debugLineNumber, QT_MESSAGELOG_FUNC).critical()
<< "While processing line" << list.join(':') << ": Found" << list.size() << "fields, expected exactly 6.";
exit(EXIT_FAILURE);
}

Expand All @@ -101,11 +99,8 @@ Airport::Airport(const QStringList& list, unsigned int debugLineNumber)
countryCode = list[3];

if (countryCode != "" && NavData::instance()->countryCodes.value(countryCode, "") == "") {
auto msg = QString("While processing line #%1 from data/airports.dat: Could not find country '%2' for airport %3 (%4, %5) in data/countryCodes.dat.")
.arg(debugLineNumber)
.arg(countryCode, id, name, city);
qCritical() << "Airport::Airport()" << msg;
QTextStream(stdout) << "CRITICAL: " << msg << Qt::endl;
QMessageLogger("airports.dat", debugLineNumber, QT_MESSAGELOG_FUNC).critical()
<< "While processing line" << list.join(':') << ": Could not find country" << countryCode;
exit(EXIT_FAILURE);
}

Expand Down
42 changes: 19 additions & 23 deletions src/GLWidget.cpp
Expand Up @@ -249,7 +249,7 @@ const QPair<double, double> GLWidget::sunZenith(const QDateTime &dateTime) const
// Methods preparing displayLists
//
void GLWidget::createPilotsList() {
qDebug() << "GLWidget::createPilotsList()";
qDebug();

if (_pilotsList == 0) {
_pilotsList = glGenLists(1);
Expand Down Expand Up @@ -460,11 +460,11 @@ void GLWidget::createPilotsList() {
glEndList();
}

qDebug() << "GLWidget::createPilotsList() -- finished";
qDebug() << "-- finished";
}

void GLWidget::createAirportsList() {
qDebug() << "GLWidget::createAirportsList() ";
qDebug();
if (_activeAirportsList == 0) {
_activeAirportsList = glGenLists(1);
}
Expand Down Expand Up @@ -553,11 +553,11 @@ void GLWidget::createAirportsList() {
}
}
glEndList();
qDebug() << "GLWidget::createAirportsList() -- finished";
qDebug() << "-- finished";
}

void GLWidget::createControllerLists() {
qDebug() << "GLWidget::createControllersLists() ";
qDebug();

// FIR polygons
if (_sectorPolygonsList == 0) {
Expand Down Expand Up @@ -602,7 +602,7 @@ void GLWidget::createControllerLists() {
}
glEndList();
}
qDebug() << "GLWidget::createControllersLists() -- finished";
qDebug() << "-- finished";
}


Expand Down Expand Up @@ -683,9 +683,8 @@ void GLWidget::createHoveredControllersLists(QSet<Controller*> controllers) {

void GLWidget::createStaticLists() {
// earth
qDebug() << "GLWidget::createStaticLists() earth";
_earthQuad = gluNewQuadric();
qDebug() << "Generating quadric texture coordinates";
_earthQuad = gluNewQuadric();
gluQuadricTexture(_earthQuad, GL_TRUE); // prepare texture coordinates
gluQuadricDrawStyle(_earthQuad, GLU_FILL); // FILL, LINE, SILHOUETTE or POINT
gluQuadricNormals(_earthQuad, GLU_SMOOTH); // NONE, FLAT or SMOOTH
Expand Down Expand Up @@ -741,7 +740,7 @@ void GLWidget::createStaticLists() {
glEndList();

// grid
qDebug() << "GLWidget::createStaticLists() gridLines";
qDebug() << "gridLines";
_gridlinesList = glGenLists(1);
glNewList(_gridlinesList, GL_COMPILE);
if (!qFuzzyIsNull(Settings::gridLineStrength())) {
Expand Down Expand Up @@ -770,7 +769,7 @@ void GLWidget::createStaticLists() {
glEndList();

// coastlines
qDebug() << "GLWidget::createStaticLists() coastLines";
qDebug() << "coastLines";
_coastlinesList = glGenLists(1);
glNewList(_coastlinesList, GL_COMPILE);
if (!qFuzzyIsNull(Settings::coastLineStrength())) {
Expand All @@ -790,7 +789,7 @@ void GLWidget::createStaticLists() {
glEndList();

// countries
qDebug() << "GLWidget::createStaticLists() countries";
qDebug() << "countries";
_countriesList = glGenLists(1);
glNewList(_countriesList, GL_COMPILE);
if (!qFuzzyIsNull(Settings::countryLineStrength())) {
Expand Down Expand Up @@ -861,7 +860,6 @@ void GLWidget::createStaticSectorLists() {
* Call drawCoordinateAxii() inside paintGL() to see where the axii are.
**/
void GLWidget::initializeGL() {
qDebug() << "GLWidget::initializeGL()";
qDebug() << "OpenGL support: " << context()->format().hasOpenGL()
<< "; 1.1:" << format().openGLVersionFlags().testFlag(QGLFormat::OpenGL_Version_1_1)
<< "; 1.2:" << format().openGLVersionFlags().testFlag(QGLFormat::OpenGL_Version_1_2)
Expand Down Expand Up @@ -1037,7 +1035,7 @@ void GLWidget::initializeGL() {
}

createStaticLists();
qDebug() << "GLWidget::initializeGL() -- finished";
qDebug() << "-- finished";
}

/**
Expand Down Expand Up @@ -1417,7 +1415,6 @@ void GLWidget::mouseReleaseEvent(QMouseEvent* event) {
}

void GLWidget::rightClick(const QPoint& pos) {
qDebug() << "GLWidget::rightClick()";
auto objects = objectsAt(pos.x(), pos.y());
int countRelevant = 0;
Pilot* pilot = 0;
Expand Down Expand Up @@ -1462,7 +1459,6 @@ void GLWidget::rightClick(const QPoint& pos) {
}
invalidatePilots();
}
qDebug() << "GLWidget::rightClick() -- finished";
}

void GLWidget::mouseDoubleClickEvent(QMouseEvent* event) {
Expand Down Expand Up @@ -1538,7 +1534,7 @@ void GLWidget::renderLabels() {

// sector controller labels
if (m_isControllerMapObjectsDirty) {
qDebug() << "GLWidget::renderLabels building controllerMapObjects";
qDebug() << "building controllerMapObjects";
m_controllerMapObjects.clear();

foreach (Controller* c, Whazzup::instance()->whazzupData().controllers) {
Expand Down Expand Up @@ -1567,7 +1563,7 @@ void GLWidget::renderLabels() {

// airport labels
if (m_isAirportsMapObjectsDirty) {
qDebug() << "GLWidget::renderLabels building airportMapObjects";
qDebug() << "building airportMapObjects";

m_activeAirportMapObjects.clear();
const QList<Airport*> activeAirportsSorted = NavData::instance()->activeAirports.values();
Expand All @@ -1591,7 +1587,7 @@ void GLWidget::renderLabels() {

// pilot labels
if (m_isPilotMapObjectsDirty) {
qDebug() << "GLWidget::renderLabels building pilotMapObjects";
qDebug() << "building pilotMapObjects";
m_pilotMapObjects.clear();

const QList<Pilot*> pilots = Whazzup::instance()->whazzupData().allPilots();
Expand Down Expand Up @@ -2353,7 +2349,7 @@ void GLWidget::drawCoordinateAxiiCurrentMatrix() const {
/////////////////////////

void GLWidget::newWhazzupData(bool isNew) {
qDebug() << "GLWidget::newWhazzupData() isNew =" << isNew;
qDebug() << "isNew =" << isNew;
if (isNew) {
// update airports
NavData::instance()->updateData(Whazzup::instance()->whazzupData());
Expand All @@ -2365,7 +2361,7 @@ void GLWidget::newWhazzupData(bool isNew) {
invalidateAirports();
m_friendPositions = Whazzup::instance()->whazzupData().friendsLatLon();
}
qDebug() << "GLWidget::newWhazzupData -- finished";
qDebug() << "-- finished";
}

void GLWidget::createFriendHighlighter() {
Expand Down Expand Up @@ -2393,14 +2389,14 @@ void GLWidget::destroyFriendHighlighter() {
//////////////////////////////////

void GLWidget::parseTexture() {
qDebug() << "GLWidget::parseTexture()";
qDebug();
GuiMessages::progress("textures", "Preparing textures...");

QImage earthTexIm;

if (Settings::glTextures()) {
QString earthTexFile = Settings::dataDirectory(QString("textures/%1").arg(Settings::glTextureEarth()));
qDebug() << "GLWidget::parseTexture() loading earth texture";
qDebug() << "loading earth texture";
GuiMessages::progress("textures", "Preparing textures: loading earth...");
earthTexIm.load(earthTexFile);
}
Expand Down Expand Up @@ -2437,7 +2433,7 @@ void GLWidget::parseTexture() {
}
}

qDebug() << "GLWidget::parseTexture() finished";
qDebug() << "-- finished";
update();
GuiMessages::remove("textures");
}
Expand Down

0 comments on commit 04fbd00

Please sign in to comment.