Skip to content

Commit

Permalink
Cleanup|Log: Printing more log messages through libdeng2
Browse files Browse the repository at this point in the history
The legacy C wrapper API now includes more versatile message
fragment printing functions.
  • Loading branch information
skyjake committed Mar 31, 2012
1 parent e14784d commit edb9aa4
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 81 deletions.
19 changes: 10 additions & 9 deletions doomsday/engine/portable/src/canvas.cpp
Expand Up @@ -33,7 +33,7 @@
#include <QCursor>
#include <QTimer>
#include <QTime>
#include <QDebug>
#include <de/Log>

#include "sys_opengl.h"
#include "sys_input.h"
Expand Down Expand Up @@ -169,11 +169,9 @@ void Canvas::grab(image_t* img, const QSize& outputSize)
memcpy(img->pixels, grabbed.constBits(), grabbed.byteCount());
img->pixelSize = grabbed.depth()/8;

#ifdef _DEBUG
qDebug() << "Canvas: grabbed" << grabbed.width() << "x" << grabbed.height()
<< "byteCount:" << grabbed.byteCount()
<< "depth:" << grabbed.depth() << "format" << grabbed.format();
#endif
LOG_DEBUG("Canvas: grabbed %i x %i, byteCount:%i depth:%i format:%i")
<< grabbed.width() << grabbed.height()
<< grabbed.byteCount() << grabbed.depth() << grabbed.format();

Q_ASSERT(img->pixelSize != 0);
}
Expand Down Expand Up @@ -268,7 +266,8 @@ void Canvas::paintGL()
}
else
{
qDebug() << "Canvas: drawing with default";
LOG_AS("Canvas");
LOG_TRACE("Drawing with default paint func.");

// If we don't know what else to draw, just draw a black screen.
glClearColor(0, 0, 0, 1);
Expand All @@ -280,14 +279,16 @@ void Canvas::paintGL()

void Canvas::focusInEvent(QFocusEvent*)
{
qDebug() << "Canvas: focus in";
LOG_AS("Canvas");
LOG_INFO("Gained focus.");

if(d->focusCallback) d->focusCallback(*this, true);
}

void Canvas::focusOutEvent(QFocusEvent*)
{
qDebug() << "Canvas: focus out";
LOG_AS("Canvas");
LOG_INFO("Lost focus.");

d->ungrabMouse();

Expand Down
7 changes: 6 additions & 1 deletion doomsday/engine/portable/src/con_main.c
Expand Up @@ -2015,18 +2015,23 @@ void Con_Message(const char *message, ...)
dd_vsnprintf(buffer, PRBUFF_SIZE, message, argptr);
va_end(argptr);

/*
#ifdef UNIX
if(!isDedicated)
{
// These messages are supposed to be visible in the real console.
fprintf(stderr, "%s", buffer);
}
#endif
*/

// These messages are always dumped. If consoleDump is set,
// Con_Printf() will dump the message for us.
if(!consoleDump)
printf("%s", buffer);
{
//printf("%s", buffer);
LegacyCore_PrintLogFragment(de2LegacyCore, buffer);
}

// Also print in the console.
Con_Printf("%s", buffer);
Expand Down
24 changes: 0 additions & 24 deletions doomsday/engine/portable/src/dd_pinit.c
Expand Up @@ -84,30 +84,6 @@ int DD_CheckArg(char* tag, const char** value)
return 1;
}

#if 0
void DD_ErrorBox(boolean error, char* format, ...)
{
char buff[200];
va_list args;

va_start(args, format);
dd_vsnprintf(buff, sizeof(buff), format, args);
va_end(args);

#ifdef WIN32
DD_Win32_SuspendMessagePump(true);
MessageBox(NULL, WIN_STRING(buff),
TEXT(DOOMSDAY_NICENAME) DOOMSDAY_VERSION_TEXT_WSTR,
(UINT) (MB_OK | (error ? MB_ICONERROR : MB_ICONWARNING)));
DD_Win32_SuspendMessagePump(false);
#endif

#ifdef UNIX
fputs(buff, stderr);
#endif
}
#endif

/**
* Compose the title for the main window.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/dd_zone.c
Expand Up @@ -229,8 +229,8 @@ void Z_Shutdown(void)
M_Free(vol);
}

printf("Z_Shutdown: Used %i volumes, total %lu bytes.\n",
numVolumes, (long unsigned int) totalMemory);
LegacyCore_PrintfLogFragmentAtLevel(de2LegacyCore, DE2_LOG_INFO,
"Z_Shutdown: Used %i volumes, total %u bytes.\n", numVolumes, totalMemory);

Sys_DestroyMutex(zoneMutex);
zoneMutex = 0;
Expand Down
28 changes: 7 additions & 21 deletions doomsday/engine/portable/src/displaymode.cpp
Expand Up @@ -25,8 +25,7 @@
#include <vector>
#include <set>
#include <algorithm>

#include <QDebug>
#include <de/Log>

static bool inited = false;

Expand Down Expand Up @@ -118,11 +117,7 @@ struct Mode : public DisplayMode
break;
}
}
#if 0
// Reduce until we must resort to fractions.
while(reduce(ratioX, ratioY)) {}

#endif
if(ratioX == 8 && ratioY == 5)
{
// This is commonly referred to as 16:10.
Expand All @@ -133,8 +128,8 @@ struct Mode : public DisplayMode

void debugPrint() const
{
qDebug() << "size" << width << "x" << height << "depth" << depth << "rate"
<< refreshRate << "ratio" << ratioX << ":" << ratioY;
LOG_DEBUG("size: %i x %i x %i, rate: %.1f Hz, ratio: %i:%i")
<< width << height << depth << refreshRate << ratioX << ratioY;
}
};

Expand Down Expand Up @@ -166,16 +161,14 @@ int DisplayMode_Init(void)
modes.insert(mode);
}

#ifdef _DEBUG
qDebug() << "Current mode is:";
LOG_DEBUG("Current mode is:");
originalMode.debugPrint();

qDebug() << "All available modes:";
LOG_DEBUG("All available modes:");
for(Modes::iterator i = modes.begin(); i != modes.end(); ++i)
{
i->debugPrint();
}
#endif

inited = true;
return true;
Expand All @@ -185,7 +178,7 @@ void DisplayMode_Shutdown(void)
{
if(!inited) return;

qDebug() << "Restoring original display mode due to shutdown.";
LOG_INFO("Restoring original display mode due to shutdown.");

// Back to the original mode.
DisplayMode_Change(&originalMode, false /*release captured*/);
Expand Down Expand Up @@ -255,13 +248,6 @@ const DisplayMode* DisplayMode_FindClosest(int width, int height, int depth, flo
// one is picked.
if(!best || score < bestScore)
{
/*
#ifdef _DEBUG
i->debugPrint();
qDebug() << "Score for" << width << "x" << height << "pixels, depth:" << depth << "bpp, freq:" << freq << "Hz is" << score;
#endif
*/

bestScore = score;
best = &*i;
}
Expand All @@ -278,7 +264,7 @@ int DisplayMode_Change(const DisplayMode* mode, boolean shouldCapture)
{
if(Mode::fromCurrent() == *mode && shouldCapture == captured)
{
qDebug() << "DisplayMode: Requested mode is the same as current, ignoring.";
LOG_DEBUG("DisplayMode: Requested mode is the same as current, ignoring.");

// Already in this mode.
return false;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/library.c
Expand Up @@ -147,9 +147,9 @@ void Library_ReleaseGames(void)
if(!lib) continue;
if(lib->isGamePlugin && lib->handle)
{
#ifdef _DEBUG
fprintf(stderr, "Library_ReleaseGames: Closing '%s'\n", Str_Text(lib->path));
#endif
LegacyCore_PrintfLogFragmentAtLevel(de2LegacyCore, DE2_LOG_DEBUG,
"Library_ReleaseGames: Closing '%s'\n", Str_Text(lib->path));

dlclose(lib->handle);
lib->handle = 0;
}
Expand All @@ -163,9 +163,9 @@ static void reopenLibraryIfNeeded(Library* lib)
assert(lib);
if(!lib->handle)
{
#ifdef _DEBUG
fprintf(stderr, "reopenLibraryIfNeeded: Opening '%s'\n", Str_Text(lib->path));
#endif
LegacyCore_PrintfLogFragmentAtLevel(de2LegacyCore, DE2_LOG_DEBUG,
"reopenLibraryIfNeeded: Opening '%s'\n", Str_Text(lib->path));

lib->handle = dlopen(Str_Text(lib->path), RTLD_NOW);
assert(lib->handle);
}
Expand Down
8 changes: 6 additions & 2 deletions doomsday/engine/portable/src/window.cpp
Expand Up @@ -50,6 +50,7 @@
#include "ui_main.h"
#include "m_args.h"

#include <de/Log>
#include <QDebug>

#ifdef MACOSX
Expand Down Expand Up @@ -802,8 +803,11 @@ static void windowFocusChanged(Canvas& canvas, bool focus)
Window* wnd = canvasToWindow(canvas);
wnd->assertWindow();

qDebug() << "windowFocusChanged" << focus << "fullscreen" << Window_IsFullscreen(wnd)
<< "hidden" << wnd->widget->isHidden() << wnd->widget->isMinimized();
LOG_DEBUG("windowFocusChanged, focus:")
<< (focus? "true" : "false")
<< " fullscreen:" << (Window_IsFullscreen(wnd)? "true" : "false")
<< " hidden:" << (wnd->widget->isHidden()? "true" : "false")
<< " minimized:" << (wnd->widget->isMinimized()? "true" : "false");

if(!focus)
{
Expand Down
13 changes: 13 additions & 0 deletions doomsday/libdeng2/include/de/c_wrapper.h
Expand Up @@ -40,6 +40,18 @@ extern "C" {
*/
DENG2_OPAQUE(LegacyCore)

// Log levels (see de::Log for description).
typedef enum legacycore_loglevel_e {
DE2_LOG_TRACE,
DE2_LOG_DEBUG,
DE2_LOG_VERBOSE,
DE2_LOG_MESSAGE,
DE2_LOG_INFO,
DE2_LOG_WARNING,
DE2_LOG_ERROR,
DE2_LOG_CRITICAL
} legacycore_loglevel_t;

DENG2_PUBLIC LegacyCore* LegacyCore_New(void* dengApp);
DENG2_PUBLIC void LegacyCore_Delete(LegacyCore* lc);
DENG2_PUBLIC void LegacyCore_SetLoopRate(LegacyCore* lc, int freqHz);
Expand All @@ -52,6 +64,7 @@ DENG2_PUBLIC void LegacyCore_Timer(LegacyCore* lc, unsigned int milliseconds, vo
DENG2_PUBLIC int LegacyCore_SetLogFile(LegacyCore* lc, const char* filePath);
DENG2_PUBLIC const char* LegacyCore_LogFile(LegacyCore* lc);
DENG2_PUBLIC void LegacyCore_PrintLogFragment(LegacyCore* lc, const char* text);
DENG2_PUBLIC void LegacyCore_PrintfLogFragmentAtLevel(LegacyCore* lc, legacycore_loglevel_t level, const char* format, ...);
DENG2_PUBLIC void LegacyCore_FlushLog(void);

/*
Expand Down
19 changes: 9 additions & 10 deletions doomsday/libdeng2/include/de/core/log.h
Expand Up @@ -30,8 +30,7 @@
#include <cstdlib>

/// Macro for accessing the local log of the current thread.
#define LOG() \
de::Log& log = de::Log::threadLog();
#define LOG() de::Log::threadLog()

/// Macro for accessing the local log of the current thread and entering
/// a new log section.
Expand All @@ -44,14 +43,14 @@
de::String __logSectionName = str; \
LOG_AS(__logSectionName.c_str());

#define LOG_TRACE(str) de::Log::threadLog().enter(de::Log::TRACE, str)
#define LOG_DEBUG(str) de::Log::threadLog().enter(de::Log::DEBUG, str)
#define LOG_VERBOSE(str) de::Log::threadLog().enter(de::Log::VERBOSE, str)
#define LOG_MSG(str) de::Log::threadLog().enter(str)
#define LOG_INFO(str) de::Log::threadLog().enter(de::Log::INFO, str)
#define LOG_WARNING(str) de::Log::threadLog().enter(de::Log::WARNING, str)
#define LOG_ERROR(str) de::Log::threadLog().enter(de::Log::ERROR, str)
#define LOG_CRITICAL(str) de::Log::threadLog().enter(de::Log::CRITICAL, str)
#define LOG_TRACE(str) LOG().enter(de::Log::TRACE, str)
#define LOG_DEBUG(str) LOG().enter(de::Log::DEBUG, str)
#define LOG_VERBOSE(str) LOG().enter(de::Log::VERBOSE, str)
#define LOG_MSG(str) LOG().enter(str)
#define LOG_INFO(str) LOG().enter(de::Log::INFO, str)
#define LOG_WARNING(str) LOG().enter(de::Log::WARNING, str)
#define LOG_ERROR(str) LOG().enter(de::Log::ERROR, str)
#define LOG_CRITICAL(str) LOG().enter(de::Log::CRITICAL, str)

#ifdef WIN32
# undef ERROR
Expand Down
7 changes: 5 additions & 2 deletions doomsday/libdeng2/include/de/legacy/legacycore.h
Expand Up @@ -22,6 +22,7 @@

#include "../libdeng2.h"
#include "../App"
#include "../Log"

namespace de {

Expand Down Expand Up @@ -113,9 +114,11 @@ class LegacyCore : public QObject
* Prints a fragment of text to the output log. The output is added to the log
* only when a complete line has been printed (i.e., newline character required).
*
* @param text Text to print.
* @param text Text to print.
* @param level Log level for the message. Only the level in effect when a newline
* is printed will be entered into the log.
*/
void printLogFragment(const char* text);
void printLogFragment(const char* text, Log::LogLevel level = Log::MESSAGE);

/**
* Returns the LegacyCore singleton instance.
Expand Down
20 changes: 20 additions & 0 deletions doomsday/libdeng2/src/c_wrapper.cpp
Expand Up @@ -25,6 +25,7 @@
#include "de/Block"
#include "de/LogBuffer"
#include <cstring>
#include <stdarg.h>

#define DENG2_LEGACYNETWORK() de::LegacyCore::instance().network()

Expand Down Expand Up @@ -112,6 +113,25 @@ void LegacyCore_PrintLogFragment(LegacyCore* lc, const char* text)
self->printLogFragment(text);
}

void LegacyCore_PrintfLogFragmentAtLevel(LegacyCore* lc, legacycore_loglevel_t level, const char* format, ...)
{
char buffer[2048];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args); /// @todo unsafe
va_end(args);

// Validate the level.
de::Log::LogLevel logLevel = de::Log::LogLevel(level);
if(level < DE2_LOG_TRACE || level > DE2_LOG_CRITICAL)
{
logLevel = de::Log::MESSAGE;
}

DENG2_SELF(LegacyCore, lc);
self->printLogFragment(buffer, logLevel);
}

void LegacyCore_FlushLog(void)
{
de::LogBuffer::appBuffer().flush();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/core/logbuffer.cpp
Expand Up @@ -203,7 +203,7 @@ void LogBuffer::flush()
{
if(message[checkPos].isSpace() ||
(message[checkPos].isPunct() && message[checkPos] != '.' &&
message[checkPos] != ','))
message[checkPos] != ',' && message[checkPos] != '-'))
{
if(!message[checkPos].isSpace())
{
Expand Down
6 changes: 5 additions & 1 deletion doomsday/libdeng2/src/data/string.cpp
Expand Up @@ -426,7 +426,11 @@ String String::patternFormat(String::const_iterator& formatIter,

case 'i':
case 'd':
output << dint(arg.asNumber());
output << dint64(arg.asNumber());
break;

case 'u':
output << duint64(arg.asNumber());
break;

case 'X':
Expand Down

0 comments on commit edb9aa4

Please sign in to comment.