From aca1660e1ede5d4b3e967b07f17ddf86f8009fa5 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 2 Aug 2017 15:22:00 +0200 Subject: [PATCH] Disable debug messages by default and downgrade a few messages. From now on, msg::debug will not display anything, unless this is a debug build, or the LOL_DEBUG environment variable is set. --- src/base/log.cpp | 15 ++++++++++++++- src/engine/ticker.cpp | 12 ++++++------ src/image/resource.cpp | 16 ++++++++++------ src/platform/android/androidapp.cpp | 16 ++++++++-------- src/platform/sdl/sdlinput.cpp | 6 +++--- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/base/log.cpp b/src/base/log.cpp index a5b9e8ad..7c47b5d9 100644 --- a/src/base/log.cpp +++ b/src/base/log.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -13,6 +13,7 @@ #include #include +#include #if defined(_WIN32) # define WIN32_LEAN_AND_MEAN @@ -72,6 +73,18 @@ void msg::error(char const *fmt, ...) void msg::helper(MessageType type, char const *fmt, va_list ap) { + /* Unless this is a debug build, ignore debug messages unless + * the LOL_DEBUG environment variable is set. */ +#if !defined LOL_BUILD_DEBUG + if (type == MessageType::Debug) + { + static char const *var = getenv("LOL_DEBUG"); + static bool const disable_debug = !var || !var[0]; + if (disable_debug) + return; + } +#endif + #if defined __ANDROID__ static int const prio[] = { diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index 27609774..c2eaf4ad 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -150,7 +150,7 @@ int Ticker::Unref(Entity *entity) void TickerData::GameThreadMain() { #if LOL_BUILD_DEBUG - msg::info("ticker game thread initialised\n"); + msg::debug("ticker game thread initialised\n"); #endif for (;;) @@ -167,7 +167,7 @@ void TickerData::GameThreadMain() drawtick.push(0); #if LOL_BUILD_DEBUG - msg::info("ticker game thread terminated\n"); + msg::debug("ticker game thread terminated\n"); #endif } #endif /* LOL_FEATURE_THREADS */ @@ -176,7 +176,7 @@ void TickerData::GameThreadMain() void TickerData::DrawThreadMain() /* unused */ { #if LOL_BUILD_DEBUG - msg::info("ticker draw thread initialised\n"); + msg::debug("ticker draw thread initialised\n"); #endif for (;;) @@ -191,7 +191,7 @@ void TickerData::DrawThreadMain() /* unused */ } #if LOL_BUILD_DEBUG - msg::info("ticker draw thread terminated\n"); + msg::debug("ticker draw thread terminated\n"); #endif } #endif /* LOL_FEATURE_THREADS */ @@ -255,7 +255,7 @@ void TickerData::GameThreadTick() data->keepalive += data->deltatime; if (data->keepalive > 10.f) { - msg::info("ticker keepalive: tick!\n"); + msg::debug("ticker keepalive: tick!\n"); data->keepalive = 0.f; } #endif diff --git a/src/image/resource.cpp b/src/image/resource.cpp index 18fa4734..77e460f4 100644 --- a/src/image/resource.cpp +++ b/src/image/resource.cpp @@ -1,8 +1,8 @@ // // Lol Engine // -// Copyright 20162017 Sam Hocevar -// Copyright 20162017 Benjamin Touky Huet +// Copyright © 2010—2017 Sam Hocevar +// Copyright © 2016—2017 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -88,13 +88,15 @@ ResourceCodecData* ResourceLoader::Load(char const *path) auto data = codec->Load(path); if (data != nullptr) { - msg::info("image::Load: Codec %s succesfully loaded %s.\n", codec->GetName(), path); + msg::debug("image::load: codec %s succesfully loaded %s.\n", + codec->GetName(), path); return data; } } //Log error, because we shouldn't be here - msg::error("image::Load: Last codec %s, Error loading resource %s.\n", last_codec->GetName(), path); + msg::error("image::load: last codec %s, error loading resource %s.\n", + last_codec->GetName(), path); return nullptr; } @@ -106,13 +108,15 @@ bool ResourceLoader::Save(char const *path, ResourceCodecData* data) last_codec = codec; if (codec->Save(path, data)) { - msg::info("image::Save: Codec %s succesfully saved %s.\n", codec->GetName(), path); + msg::info("image::save: codec %s succesfully saved %s.\n", + codec->GetName(), path); return true; } } //Log error, because we shouldn't be here - msg::error("image::Save: Last codec %s, Error saving resource %s.\n", last_codec->GetName(), path); + msg::error("image::save: last codec %s, error saving resource %s.\n", + last_codec->GetName(), path); return false; } diff --git a/src/platform/android/androidapp.cpp b/src/platform/android/androidapp.cpp index 312858ca..e7662bd3 100644 --- a/src/platform/android/androidapp.cpp +++ b/src/platform/android/androidapp.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -42,7 +42,7 @@ AAssetManager *g_assets; extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) { - msg::info("Java layer loading library, vm=0x%08lx", (long)(intptr_t)vm); + msg::debug("Java layer loading library, vm=0x%08lx", (long)(intptr_t)vm); return JNI_VERSION_1_4; } @@ -152,7 +152,7 @@ int lol::AndroidAppData::CreateDisplay() eglQuerySurface(m_display, m_surface, EGL_HEIGHT, &h); /* Launch our renderer */ - msg::info("Java layer initialising renderer (%dx%d)", w, h); + msg::debug("Java layer initialising renderer (%dx%d)", w, h); Video::Setup(ivec2(w, h)); return 0; @@ -267,8 +267,8 @@ AndroidAppData *g_data; void android_main(android_app* native_app) { - msg::info("Java layer calling android_main() for app 0x%08lx", - (long)native_app); + msg::debug("Java layer calling android_main() for app 0x%08lx", + (long)native_app); /* Register native activity */ g_activity = native_app->activity; @@ -278,7 +278,7 @@ void android_main(android_app* native_app) jint res = g_activity->vm->GetEnv((void **)&jni_env, JNI_VERSION_1_2); if (res < 0) { - msg::info("JVM environment not found, trying to attach thread\n"); + msg::debug("JVM environment not found, trying to attach thread\n"); res = g_activity->vm->AttachCurrentThread(&jni_env, nullptr); } if (res < 0) @@ -329,7 +329,7 @@ void android_main(android_app* native_app) source->process(native_app, source); } - msg::info("Java layer running real main()\n"); + msg::debug("Java layer running real main()\n"); /* Call the user's main() function. One of these will work. */ lol_android_main(); @@ -341,7 +341,7 @@ lol::AndroidApp::AndroidApp(char const *title, ivec2 res, float fps) : m_data(g_data) { /* Launch our ticker */ - msg::info("Java layer initialising ticker at %g fps", fps); + msg::debug("Java layer initialising ticker at %g fps", fps); Ticker::Setup(fps); m_data->m_wanted_resolution = res; diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index 74a3366b..a9214756 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -300,7 +300,7 @@ void SdlInputData::Tick(float seconds) } m_keyboard->SetKey(sc2, !m_keyboard->GetKey(sc2)); /* DEBUG STUFF - msg::info("Repeat: 0x%02x : %s/%s/%s/%i\n", + msg::debug("Repeat: 0x%02x : %s/%s/%s/%i\n", (int)m_keyboard, ScanCodeToText(sc2).C(), ScanCodeToName(sc2).C(), m_keyboard->GetKey(sc2) ? "up" : "down", event.key.repeat); */ @@ -317,7 +317,7 @@ void SdlInputData::Tick(float seconds) m_keyboard->SetKey(sc, event.type == SDL_KEYDOWN); /* DEBUG STUFF - msg::info("Repeat: 0x%02x : %s/%s/%s/%i\n", + msg::debug("Repeat: 0x%02x : %s/%s/%s/%i\n", (int)m_keyboard, ScanCodeToText(sc).C(), ScanCodeToName(sc).C(), event.type == SDL_KEYDOWN ? "up" : "down", event.key.repeat); */