Refactored logging system using iostream
This commit is contained in:
parent
a8ae50df94
commit
46e9e73793
9 changed files with 87 additions and 15 deletions
|
@ -61,7 +61,7 @@ DefinitionNode* Layers::getLayer(int position) const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logWarning("Asked for a undefined layer %d on a total of %d", position, (int)layers.size());
|
Logs::warning() << "Asked for a undefined layer " << position << " on a total of " << (int)layers.size() << std::endl;
|
||||||
return null_layer;
|
return null_layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ int Layers::findLayer(DefinitionNode* layer) const
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
logWarning("Layer %p (%s) not found, on a total of %d", layer, layer->getName().c_str(), (int)layers.size());
|
Logs::warning() << "Layer " << layer << " (" << layer->getName() << " not found, on a total of " << (int)layers.size() << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ int Layers::addLayer(DefinitionNode* layer)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logWarning("Add layer ignored because limit of %d reached", max_layer_count);
|
Logs::warning() << "Add layer ignored because limit of " << max_layer_count << " reached" << std::endl;
|
||||||
delete layer;
|
delete layer;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ void Layers::removeLayer(int position)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logWarning("Removing unknown layer %d on %d from '%s'", position, (int)layers.size(), getName().c_str());
|
Logs::warning() << "Removing unknown layer " << position << " on " << (int)layers.size() << " from '" << getName() << "'" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ MainModelerWindow::MainModelerWindow()
|
||||||
scenery = new Scenery();
|
scenery = new Scenery();
|
||||||
scenery->autoPreset();
|
scenery->autoPreset();
|
||||||
|
|
||||||
logDebug("Initialized scenery:\n%s", QString::fromStdString(scenery->toString()).toLatin1().data());
|
Logs::debug() << "Initialized scenery:\n" << scenery->toString() << std::endl;
|
||||||
|
|
||||||
renderer = new OpenGLRenderer(scenery);
|
renderer = new OpenGLRenderer(scenery);
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ void OpenGLRenderer::initialize()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logError("Failed to initialize OpenGL bindings");
|
Logs::error() << "Failed to initialize OpenGL bindings" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ void OpenGLRenderer::paint()
|
||||||
int error_code;
|
int error_code;
|
||||||
while ((error_code = glGetError()) != GL_NO_ERROR)
|
while ((error_code = glGetError()) != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
logWarning("[OpenGL] ERROR : %s", (const char*)gluErrorString(error_code));
|
Logs::warning() << "[OpenGL] ERROR : " << (const char*)gluErrorString(error_code) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ void OpenGLShaderProgram::addVertexSource(QString path)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logError() << "Can't open vertex file " << file.fileName();
|
Logs::error() << "Can't open vertex file " << file.fileName().toStdString() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ void OpenGLShaderProgram::addFragmentSource(QString path)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logError() << "Can't open fragment file " << file.fileName();
|
Logs::error() << "Can't open fragment file " << file.fileName().toStdString() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ std::string DataFile::findDir(const std::string &relpath)
|
||||||
|
|
||||||
bool DataFile::tryDataDir(const QDir &dir)
|
bool DataFile::tryDataDir(const QDir &dir)
|
||||||
{
|
{
|
||||||
logDebug("[System] Try data dir %s", dir.absolutePath().toLocal8Bit().data());
|
Logs::debug() << "[System] Try data dir " << dir.absolutePath().toStdString() << std::endl;
|
||||||
return dir.exists("data/.paysages_data");
|
return dir.exists("data/.paysages_data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,13 +58,13 @@ std::string DataFile::initDataDir()
|
||||||
std::string parent = locateDataDir();
|
std::string parent = locateDataDir();
|
||||||
if (parent.empty())
|
if (parent.empty())
|
||||||
{
|
{
|
||||||
logWarning("[System] Data files not found");
|
Logs::warning() << "[System] Data files not found" << std::endl;
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string result = QDir(QString::fromStdString(parent)).absoluteFilePath("data").toStdString();
|
std::string result = QDir(QString::fromStdString(parent)).absoluteFilePath("data").toStdString();
|
||||||
logDebug("[System] Data files found : %s", result.c_str());
|
Logs::debug() << "[System] Data files found : " << result << std::endl;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,52 @@
|
||||||
#include "Logs.h"
|
#include "Logs.h"
|
||||||
|
|
||||||
|
static std::ostream NULL_STREAM(0);
|
||||||
|
static bool enabled = true;
|
||||||
|
|
||||||
|
std::ostream &Logs::debug()
|
||||||
|
{
|
||||||
|
#ifdef NDEBUG
|
||||||
|
return NULL_STREAM;
|
||||||
|
#else
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
std::cout << "DEBUG - ";
|
||||||
|
return std::cout;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL_STREAM;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &Logs::warning()
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
std::cerr << "WARN - ";
|
||||||
|
return std::cerr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL_STREAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &Logs::error()
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR - ";
|
||||||
|
return std::cerr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL_STREAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logs::disable()
|
||||||
|
{
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
|
@ -3,8 +3,26 @@
|
||||||
|
|
||||||
#include "system_global.h"
|
#include "system_global.h"
|
||||||
|
|
||||||
#define logDebug qDebug
|
#include <iostream>
|
||||||
#define logWarning qWarning
|
|
||||||
#define logError qCritical
|
namespace paysages {
|
||||||
|
namespace system {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger streams
|
||||||
|
*/
|
||||||
|
class Logs
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static std::ostream &debug();
|
||||||
|
static std::ostream &warning();
|
||||||
|
static std::ostream &error();
|
||||||
|
|
||||||
|
// Disable all logs from now on
|
||||||
|
static void disable();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // LOGS_H
|
#endif // LOGS_H
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
namespace paysages {
|
namespace paysages {
|
||||||
namespace system {
|
namespace system {
|
||||||
|
class Logs;
|
||||||
class PackStream;
|
class PackStream;
|
||||||
class ParallelWork;
|
class ParallelWork;
|
||||||
class ParallelPool;
|
class ParallelPool;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "BaseTestCase.h"
|
#include "BaseTestCase.h"
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include "Logs.h"
|
||||||
|
|
||||||
void noMessageOutput(QtMsgType, const QMessageLogContext&, const QString&)
|
void noMessageOutput(QtMsgType, const QMessageLogContext&, const QString&)
|
||||||
{
|
{
|
||||||
|
@ -11,6 +12,7 @@ int main(int argc, char **argv)
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
qInstallMessageHandler(noMessageOutput);
|
qInstallMessageHandler(noMessageOutput);
|
||||||
|
Logs::disable();
|
||||||
|
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
result = RUN_ALL_TESTS();
|
result = RUN_ALL_TESTS();
|
||||||
|
|
Loading…
Reference in a new issue