Added mandatory logger information

This commit is contained in:
Michaël Lemaire 2015-12-13 20:08:38 +01:00
parent d6444028f9
commit e0ba87e4e5
23 changed files with 85 additions and 79 deletions

View file

@ -110,8 +110,8 @@ bool DefinitionNode::applyDiff(const DefinitionDiff *diff, bool) {
if (diff->getTypeName() == type_name) {
return true;
} else {
Logs::error() << "[Definition] Can't apply " << diff->getTypeName() << " diff to " << getName() << " "
<< type_name << " node" << endl;
Logs::error("Definition") << "Can't apply " << diff->getTypeName() << " diff to " << getName() << " "
<< type_name << " node" << endl;
return false;
}
}
@ -155,8 +155,8 @@ void DefinitionNode::save(PackStream *stream) const {
child->save(stream);
} else {
// Child size not known, write it to a temporary stream to know it
Logs::debug() << "[Definition] Unknown size for child " << child->name
<< ", unefficient writing to temporary stream" << endl;
Logs::debug("Definition") << "Unknown size for child " << child->name
<< ", unefficient writing to temporary stream" << endl;
PackStream substream;
child->save(&substream);
stream->writeFromBuffer(substream, true);
@ -183,7 +183,7 @@ void DefinitionNode::load(PackStream *stream) {
// TODO Ask subclass if it can instanciate a child
// Else skip length of unknown child
stream->skipBytes(child_size);
Logs::warning() << "[Definition] Skipped unknown child '" << child_name << "'" << endl;
Logs::warning("Definition") << "Skipped unknown child '" << child_name << "'" << endl;
}
}
}
@ -196,13 +196,13 @@ void DefinitionNode::copy(DefinitionNode *destination) const {
if (dest_child) {
child->copy(dest_child);
} else {
Logs::warning() << "[Definition] Can't copy to child " << child->name << " of "
<< destination->getTypeName() << endl;
Logs::warning("Definition") << "Can't copy to child " << child->name << " of "
<< destination->getTypeName() << endl;
}
}
} else {
Logs::error() << "[Definition] Can't copy from " << getTypeName() << " to " << destination->getTypeName()
<< endl;
Logs::error("Definition") << "Can't copy from " << getTypeName() << " to " << destination->getTypeName()
<< endl;
}
}
@ -226,8 +226,8 @@ void DefinitionNode::removeChild(DefinitionNode *child) {
child->parent = NULL;
children.erase(it);
} else {
Logs::warning() << "[Definition] Trying to remove not found child '" << child->name << "' from '" << name << "'"
<< endl;
Logs::warning("Definition") << "Trying to remove not found child '" << child->name << "' from '" << name << "'"
<< endl;
}
}

View file

@ -31,6 +31,6 @@ void DefinitionWatcher::startWatching(const DefinitionNode *root, const string &
if (node) {
node->addWatcher(this, init_diff);
} else {
Logs::warning() << "[Definition] Node not found for watching : " << path << endl;
Logs::warning("Definition") << "Node not found for watching : " << path << endl;
}
}

View file

@ -61,7 +61,7 @@ void DiffManager::undo() {
watcher->nodeChanged(node, diff);
}
} else {
Logs::error() << "Can't find node to undo diff : " << diff->getPath() << endl;
Logs::error("Definition") << "Can't find node to undo diff : " << diff->getPath() << endl;
}
}
}
@ -81,7 +81,7 @@ void DiffManager::redo() {
watcher->nodeChanged(node, diff);
}
} else {
Logs::error() << "Can't find node to redo diff : " << diff->getPath() << endl;
Logs::error("Definition") << "Can't find node to redo diff : " << diff->getPath() << endl;
}
}
}

View file

@ -30,7 +30,8 @@ void FloatNode::copy(DefinitionNode *destination) const {
if (destination->getTypeName() == getTypeName()) {
((FloatNode *)destination)->value = value;
} else {
Logs::error() << "[Definition] Can't copy from " << getTypeName() << " to " << destination->getTypeName() << endl;
Logs::error("Definition") << "Can't copy from " << getTypeName() << " to " << destination->getTypeName()
<< endl;
}
}
@ -61,7 +62,8 @@ bool FloatNode::applyDiff(const DefinitionDiff *diff, bool backward) {
value = next;
return true;
} else {
Logs::error() << "[Definition] Can't apply float diff " << previous << " => " << next << " to " << getName() << endl;
Logs::error("Definition") << "Can't apply float diff " << previous << " => " << next << " to " << getName()
<< endl;
return false;
}
}

View file

@ -30,7 +30,8 @@ void IntNode::copy(DefinitionNode *destination) const {
if (destination->getTypeName() == getTypeName()) {
((IntNode *)destination)->value = value;
} else {
Logs::error() << "[Definition] Can't copy from " << getTypeName() << " to " << destination->getTypeName() << endl;
Logs::error("Definition") << "Can't copy from " << getTypeName() << " to " << destination->getTypeName()
<< endl;
}
}
@ -61,7 +62,8 @@ bool IntNode::applyDiff(const DefinitionDiff *diff, bool backward) {
value = next;
return true;
} else {
Logs::error() << "[Definition] Can't apply int diff " << previous << " => " << next << " to " << getName() << endl;
Logs::error("Definition") << "Can't apply int diff " << previous << " => " << next << " to " << getName()
<< endl;
return false;
}
}

View file

@ -68,8 +68,8 @@ DefinitionNode *Layers::getLayer(int position) const {
if (position >= 0 and position < (int)layers.size()) {
return layers[position];
} else {
Logs::warning() << "Asked for a undefined layer " << position << " on a total of " << (int)layers.size()
<< endl;
Logs::warning("Definition") << "Asked for a undefined layer " << position << " on a total of "
<< (int)layers.size() << endl;
return null_layer;
}
}
@ -81,12 +81,13 @@ bool Layers::applyDiff(const DefinitionDiff *diff, bool backward) {
if ((not backward and op == LayersDiff::LAYER_ADDED) or (backward and op == LayersDiff::LAYER_REMOVED)) {
if (layer_count >= max_layer_count) {
Logs::warning() << "Add layer ignored because limit of " << max_layer_count << " reached" << endl;
Logs::warning("Definition") << "Add layer ignored because limit of " << max_layer_count << " reached"
<< endl;
return false;
} else {
int position = layer_diff->getLayer1();
if (position < 0 or position > layer_count) {
Logs::error() << "Add layer ignored because requested position was incorrect" << endl;
Logs::error("Definition") << "Add layer ignored because requested position was incorrect" << endl;
return false;
} else {
DefinitionNode *layer = layer_constructor(this, "temp");
@ -103,8 +104,8 @@ bool Layers::applyDiff(const DefinitionDiff *diff, bool backward) {
} else if ((not backward and op == LayersDiff::LAYER_REMOVED) or (backward and op == LayersDiff::LAYER_ADDED)) {
int position = layer_diff->getLayer1();
if (position < 0 or position >= layer_count) {
Logs::warning() << "Removing unknown layer " << position << " on " << layer_count << " from '" << getName()
<< "'" << endl;
Logs::warning("Definition") << "Removing unknown layer " << position << " on " << layer_count << " from '"
<< getName() << "'" << endl;
return false;
} else {
DefinitionNode *removed = layers[position];

View file

@ -31,7 +31,8 @@ void NoiseNode::copy(DefinitionNode *destination) const {
if (destination->getTypeName() == getTypeName()) {
noise->copy(((NoiseNode *)destination)->noise);
} else {
Logs::error() << "[Definition] Can't copy from " << getTypeName() << " to " << destination->getTypeName() << endl;
Logs::error("Definition") << "Can't copy from " << getTypeName() << " to " << destination->getTypeName()
<< endl;
}
}

View file

@ -52,7 +52,7 @@ Scenery::FileOperationResult Scenery::saveGlobal(const string &filepath) const {
stream.write(&version_header);
stream.write(&app_header);
Logs::debug() << "[Definition] Scenery saved to file: " << filepath << endl;
Logs::debug("Definition") << "Scenery saved to file: " << filepath << endl;
return FILE_OPERATION_OK;
}
@ -90,7 +90,7 @@ Scenery::FileOperationResult Scenery::loadGlobal(const string &filepath) {
return FILE_OPERATION_APP_MISMATCH;
}
Logs::debug() << "[Definition] Scenery loaded from file: " << filepath << endl;
Logs::debug("Definition") << "Scenery loaded from file: " << filepath << endl;
return FILE_OPERATION_OK;
}
@ -115,10 +115,10 @@ void Scenery::redo() {
_nodeclass_ *tnode = (_nodeclass_ *)node; \
tnode->setValue(_value_); \
} else { \
Logs::warning() << "[Definition] Node " << path << " of wrong type for value " << value << endl; \
Logs::warning("Definition") << "Node " << path << " of wrong type for value " << value << endl; \
} \
} else { \
Logs::warning() << "[Definition] Can't find node " << path << " to set to " << value << endl; \
Logs::warning("Definition") << "Can't find node " << path << " to set to " << value << endl; \
}
void Scenery::set(const string &path, const int &value) {
@ -146,7 +146,7 @@ void Scenery::autoPreset(RandomGenerator &random) {
validate();
Logs::debug() << "[Definition] New scenery generated from seed " << random.getSeed() << endl;
Logs::debug("Definition") << "New scenery generated from seed " << random.getSeed() << endl;
}
void Scenery::autoPreset(unsigned int seed) {

View file

@ -15,7 +15,7 @@ FloatPropertyBind::FloatPropertyBind(MainModelerWindow *window, const QString &o
connect(item, SIGNAL(changed(double)), this, SLOT(propertyChanged(double)));
} else {
item = NULL;
Logs::error() << "Can't find object :" << object_name.toStdString() << endl;
Logs::error("UI") << "Can't find object :" << object_name.toStdString() << endl;
}
}

View file

@ -13,7 +13,7 @@ IntPropertyBind::IntPropertyBind(MainModelerWindow *window, const QString &objec
connect(item, SIGNAL(changed(int)), this, SLOT(propertyChanged(int)));
} else {
item = NULL;
Logs::error() << "Can't find object :" << object_name.toStdString() << endl;
Logs::error("UI") << "Can't find object :" << object_name.toStdString() << endl;
}
}

View file

@ -74,7 +74,7 @@ void MainModelerWindow::setQmlProperty(const QString &objectName, const QString
if (item) {
item->setProperty(propertyName.toLocal8Bit(), value);
} else {
Logs::error() << "QML object not found :" << objectName.toStdString() << endl;
Logs::error("UI") << "QML object not found :" << objectName.toStdString() << endl;
}
}
@ -84,7 +84,7 @@ void MainModelerWindow::connectQmlSignal(const QString &objectName, const char *
if (item) {
connect(item, signal, receiver, method);
} else {
Logs::error() << "QML object not found :" << objectName.toStdString() << endl;
Logs::error("UI") << "QML object not found :" << objectName.toStdString() << endl;
}
}
@ -137,8 +137,8 @@ void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) {
} else if (event->key() == Qt::Key_F6) {
render_process->showPreviousRender();
} else if (event->key() == Qt::Key_F12) {
Logs::warning() << "Current scenery dump:" << endl
<< scenery->toString() << endl;
Logs::warning("UI") << "Current scenery dump:" << endl
<< scenery->toString() << endl;
} else if (event->key() == Qt::Key_N) {
if (event->modifiers() & Qt::ControlModifier) {
newFile();

View file

@ -74,7 +74,7 @@ void OpenGLRenderer::prepare() {
void OpenGLRenderer::checkForErrors(const string &domain) {
int error_code;
while ((error_code = functions->glGetError()) != GL_NO_ERROR) {
Logs::warning() << "[OpenGL] Error in " << domain << " : " << error_code << endl;
Logs::warning("OpenGL") << "Error in " << domain << " : " << error_code << endl;
}
}
@ -92,8 +92,8 @@ void OpenGLRenderer::initialize() {
bool init = functions->initializeOpenGLFunctions();
if (init) {
Logs::debug() << "[OpenGL] renderer started (version " << functions->glGetString(GL_VERSION)
<< ", glsl version " << functions->glGetString(GL_SHADING_LANGUAGE_VERSION) << ")" << endl;
Logs::debug("OpenGL") << "Renderer started (version " << functions->glGetString(GL_VERSION) << ", glsl version "
<< functions->glGetString(GL_SHADING_LANGUAGE_VERSION) << ")" << endl;
prepareOpenGLState();
@ -109,7 +109,7 @@ void OpenGLRenderer::initialize() {
checkForErrors("initialize");
ready = true;
} else {
Logs::error() << "[OpenGL] Failed to initialize api bindings" << endl;
Logs::error("OpenGL") << "Failed to initialize api bindings" << endl;
}
}

View file

@ -30,7 +30,7 @@ void OpenGLShaderProgram::addVertexSource(const string &path) {
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
source_vertex += QString(file.readAll()).toStdString();
} else {
Logs::error() << "[OpenGL] Can't open vertex file " << file.fileName().toStdString() << endl;
Logs::error("OpenGL") << "Can't open vertex file " << file.fileName().toStdString() << endl;
}
}
@ -39,7 +39,7 @@ void OpenGLShaderProgram::addFragmentSource(const string &path) {
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
source_fragment += QString(file.readAll()).toStdString();
} else {
Logs::error() << "[OpenGL] Can't open fragment file " << file.fileName().toStdString() << endl;
Logs::error("OpenGL") << "Can't open fragment file " << file.fileName().toStdString() << endl;
}
}
@ -57,13 +57,13 @@ void OpenGLShaderProgram::compile() {
program->bindAttributeLocation("uv", 1);
if (not program->link()) {
Logs::warning() << "[OpenGL] Error while compiling shader " << name << endl
<< program->log().toStdString() << endl;
Logs::warning("OpenGL") << "Error while compiling shader " << name << endl
<< program->log().toStdString() << endl;
} else if (program->log().length() > 0) {
Logs::debug() << "[OpenGL] Shader " << name << " compilation output:" << endl
<< program->log().toStdString() << endl;
Logs::debug("OpenGL") << "Shader " << name << " compilation output:" << endl
<< program->log().toStdString() << endl;
} else {
Logs::debug() << "[OpenGL] Shader " << name << " compiled" << endl;
Logs::debug("OpenGL") << "Shader " << name << " compiled" << endl;
}
}

View file

@ -62,7 +62,7 @@ void OpenGLSkybox::initialize() {
}
void OpenGLSkybox::update() {
Logs::debug() << "[OpenGL] Updating atmosphere textures" << endl;
Logs::debug("OpenGL") << "Updating atmosphere textures" << endl;
SoftwareBrunetonAtmosphereRenderer *bruneton =
(SoftwareBrunetonAtmosphereRenderer *)renderer->getAtmosphereRenderer();
@ -91,8 +91,7 @@ void OpenGLSkybox::nodeChanged(const DefinitionNode *node, const DefinitionDiff
DefinitionWatcher::nodeChanged(node, diff);
}
void OpenGLSkybox::floatNodeChanged(const string &path, double new_value, double)
{
void OpenGLSkybox::floatNodeChanged(const string &path, double new_value, double) {
OpenGLSharedState *state = renderer->getSharedState();
if (path == path_humidity) {

View file

@ -35,7 +35,7 @@ OpenGLVariable::~OpenGLVariable() {
delete[] value_texture_data;
if (texture_id) {
Logs::warning() << "[OpenGL] Texture ID not freed " << texture_id << endl;
Logs::warning("OpenGL") << "Texture ID not freed " << texture_id << endl;
}
}

View file

@ -23,7 +23,7 @@ OpenGLVertexArray::OpenGLVertexArray(bool has_uv, bool strip) : has_uv(has_uv) {
OpenGLVertexArray::~OpenGLVertexArray() {
if (vao || vbo_vertex || vbo_uv) {
Logs::warning() << "[OpenGL] VertexArray not freed in OpenGL state before destructor called" << endl;
Logs::warning("OpenGL") << "VertexArray not freed in OpenGL state before destructor called" << endl;
}
free(array_vertex);
@ -79,7 +79,7 @@ void OpenGLVertexArray::set(int index, const Vector3 &location, double u, double
array_uv[index * 2 + 1] = v;
changed = true;
} else {
Logs::error() << "[OpenGL] Setting vertex data outside of array bounds" << endl;
Logs::error("OpenGL") << "Setting vertex data outside of array bounds" << endl;
}
}
@ -91,7 +91,7 @@ void OpenGLVertexArray::get(int index, Vector3 *location, double *u, double *v)
*u = array_uv[index * 2];
*v = array_uv[index * 2 + 1];
} else {
Logs::error() << "[OpenGL] Getting vertex data outside of array bounds" << endl;
Logs::error("OpenGL") << "Getting vertex data outside of array bounds" << endl;
}
}

View file

@ -58,7 +58,7 @@ void OpenGLWater::update() {
state->set("waterMaterialShininess", water->material->shininess);
state->set("waterMaterialHardness", water->material->hardness);
Logs::debug() << "[OpenGL] Updating simplex texture" << endl;
Logs::debug("OpenGL") << "Updating simplex texture" << endl;
state->set("simplexSampler", NoiseFunctionSimplex::getNormalTexture(), true, true);
}

View file

@ -100,7 +100,7 @@ BaseCloudLayerRenderer *CloudsRenderer::getLayerRenderer(unsigned int layer) {
if (layer < layer_renderers.size()) {
return layer_renderers[layer];
} else {
Logs::warning() << "Asked for unknown layer renderer " << layer << endl;
Logs::warning("Software.Clouds") << "Asked for unknown layer renderer " << layer << endl;
return fake_renderer;
}
}
@ -109,7 +109,7 @@ BaseCloudsModel *CloudsRenderer::getLayerModel(unsigned int layer) {
if (layer < layer_models.size()) {
return layer_models[layer];
} else {
Logs::warning() << "Asked for unknown layer model" << layer << endl;
Logs::warning("Software.Clouds") << "Asked for unknown layer model" << layer << endl;
return fake_model;
}
}
@ -121,7 +121,7 @@ void CloudsRenderer::setLayerModel(unsigned int layer, BaseCloudsModel *model, b
}
layer_models[layer] = model;
} else {
Logs::warning() << "Asked to set an unknown layer model" << layer << endl;
Logs::warning("Software.Clouds") << "Asked to set an unknown layer model" << layer << endl;
delete model;
}
}

View file

@ -72,7 +72,7 @@ void RenderProgress::exitSub() {
void RenderProgress::end() {
if (subs.size() > 0) {
Logs::error() << subs.size() << " progress subs remaining at the end of render" << endl;
Logs::error("Software") << subs.size() << " progress subs remaining at the end of render" << endl;
}
end_time = Time::getRelativeTimeMs();

View file

@ -21,7 +21,7 @@ string DataFile::findDir(const string &relpath) {
}
bool DataFile::tryDataDir(const QDir &dir) {
Logs::debug() << "[System] Try data dir " << dir.absolutePath().toStdString() << endl;
Logs::debug("System") << "Try data dir " << dir.absolutePath().toStdString() << endl;
return dir.exists("data/.paysages_data");
}
@ -50,11 +50,11 @@ string DataFile::locateDataDir() {
string DataFile::initDataDir() {
string parent = locateDataDir();
if (parent.empty()) {
Logs::warning() << "[System] Data files not found" << endl;
Logs::warning("System") << "Data files not found" << endl;
return parent;
} else {
string result = QDir(QString::fromStdString(parent)).absoluteFilePath("data").toStdString();
Logs::debug() << "[System] Data files found : " << result << endl;
Logs::debug("System") << "Data files found : " << result << endl;
return result;
}
}

View file

@ -25,12 +25,12 @@ typedef basic_onullstream<char> onullstream;
static onullstream NULL_STREAM;
static bool enabled = true;
ostream &Logs::debug() {
ostream &Logs::debug(const string &logger) {
#ifdef NDEBUG
return NULL_STREAM;
#else
if (enabled) {
cout << "DEBUG - ";
cout << "DEBUG [" << logger << "] ";
return cout;
} else {
return NULL_STREAM;
@ -38,26 +38,26 @@ ostream &Logs::debug() {
#endif
}
ostream &Logs::warning() {
ostream &Logs::warning(const string &logger) {
if (enabled) {
cerr << "WARN - ";
cerr << "WARN [" << logger << "] ";
return cerr;
} else {
return NULL_STREAM;
}
}
ostream &Logs::error() {
ostream &Logs::error(const string &logger) {
if (enabled) {
cerr << "ERROR - ";
cerr << "ERROR [" << logger << "] ";
return cerr;
} else {
return NULL_STREAM;
}
}
void Logs::debugTimestamp(const string &message) {
debug() << Time::getRelativeTimeMs() << " - " << message << endl;
void Logs::debugTimestamp(const string &logger, const string &message) {
debug(logger) << Time::getRelativeTimeMs() << " - " << message << endl;
}
void Logs::disable() {

View file

@ -13,12 +13,12 @@ namespace system {
*/
class SYSTEMSHARED_EXPORT Logs {
public:
static ostream &debug();
static ostream &warning();
static ostream &error();
static ostream &debug(const string &logger);
static ostream &warning(const string &logger);
static ostream &error(const string &logger);
// Log a timestamp on the debug output
static void debugTimestamp(const string &message);
static void debugTimestamp(const string &logger, const string &message);
// Disable all logs from now on
static void disable();

View file

@ -24,8 +24,8 @@ PackStream::PackStream(const PackStream *other) {
file = NULL;
buffer = new QByteArray();
if (other->file) {
Logs::error() << "Try to read from a substream bound to a file: " << other->file->fileName().toStdString()
<< endl;
Logs::error("System") << "Try to read from a substream bound to a file: "
<< other->file->fileName().toStdString() << endl;
stream = new QDataStream(buffer, QIODevice::ReadOnly);
} else {
stream = new QDataStream(other->buffer, QIODevice::ReadOnly);
@ -86,8 +86,8 @@ void PackStream::write(const string &value) {
void PackStream::writeFromBuffer(const PackStream &other, bool prepend_size) {
if (other.file) {
Logs::error() << "Try to write from a substream bound to a file: " << other.file->fileName().toStdString()
<< endl;
Logs::error("System") << "Try to write from a substream bound to a file: "
<< other.file->fileName().toStdString() << endl;
} else {
if (prepend_size) {
int buffer_size = (int)other.buffer->size();
@ -99,7 +99,8 @@ void PackStream::writeFromBuffer(const PackStream &other, bool prepend_size) {
string PackStream::getBuffer() {
if (file) {
Logs::error() << "Try to get buffer on a stream bound to a file: " << file->fileName().toStdString() << endl;
Logs::error("System") << "Try to get buffer on a stream bound to a file: " << file->fileName().toStdString()
<< endl;
return "";
} else {
return buffer->toStdString();