Browse Source

Added function SetTraceLogTypes()

Trace log messages could be configured with this function to select wich
ones are shown
pull/432/head
raysan5 7 years ago
parent
commit
e517d8fd16
3 changed files with 32 additions and 23 deletions
  1. +2
    -2
      src/core.c
  2. +7
    -6
      src/raylib.h
  3. +23
    -15
      src/utils.c

+ 2
- 2
src/core.c View File

@ -329,7 +329,7 @@ static double updateTime, drawTime; // Time measures for update and draw
static double frameTime = 0.0; // Time measure for one frame
static double targetTime = 0.0; // Desired time for one frame, if 0 not applied
static char configFlags = 0; // Configuration flags (bit based)
static unsigned char configFlags = 0; // Configuration flags (bit based)
static bool showLogo = false; // Track if showing logo at init is enabled
#if defined(SUPPORT_GIF_RECORDING)
@ -1138,7 +1138,7 @@ void ShowLogo(void)
}
// Setup window configuration flags (view FLAGS)
void SetConfigFlags(char flags)
void SetConfigFlags(unsigned char flags)
{
configFlags = flags;

+ 7
- 6
src/raylib.h View File

@ -514,11 +514,11 @@ typedef struct VrDeviceInfo {
//----------------------------------------------------------------------------------
// Trace log type
typedef enum {
LOG_INFO = 0,
LOG_WARNING,
LOG_ERROR,
LOG_DEBUG,
LOG_OTHER
LOG_INFO = 1,
LOG_WARNING = 2,
LOG_ERROR = 4,
LOG_DEBUG = 8,
LOG_OTHER = 16
} LogType;
// Shader location point type
@ -727,7 +727,8 @@ RLAPI Matrix MatrixIdentity(void); // Returns ide
// Misc. functions
RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags)
RLAPI void SetConfigFlags(char flags); // Setup window configuration flags (view FLAGS)
RLAPI void SetConfigFlags(unsigned char flags); // Setup window configuration flags (view FLAGS)
RLAPI void SetTraceLogTypes(unsigned char types); // Enable trace log message types (bit flags based)
RLAPI void TraceLog(int logType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
RLAPI void TakeScreenshot(const char *fileName); // Takes a screenshot of current screen (saved a .png)
RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included)

+ 23
- 15
src/utils.c View File

@ -16,9 +16,6 @@
* Show TraceLog() output messages
* NOTE: By default LOG_DEBUG traces not shown
*
* #define SUPPORT_TRACELOG_DEBUG
* Show TraceLog() LOG_DEBUG messages
*
* DEPENDENCIES:
* stb_image_write - BMP/PNG writting functions
*
@ -45,7 +42,6 @@
**********************************************************************************************/
#define SUPPORT_TRACELOG // Output tracelog messages
//#define SUPPORT_TRACELOG_DEBUG // Avoid LOG_DEBUG messages tracing
#include "raylib.h" // WARNING: Required for: LogType enum
#include "utils.h"
@ -63,12 +59,16 @@
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "external/stb_image_write.h" // Required for: stbi_write_bmp(), stbi_write_png()
#include "external/stb_image_write.h" // Required for: stbi_write_bmp(), stbi_write_png()
#endif
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
// Log types messages supported flags (bit based)
static unsigned char logTypeFlags = LOG_INFO | LOG_WARNING | LOG_ERROR;
#if defined(PLATFORM_ANDROID)
AAssetManager *assetManager;
#endif
@ -87,16 +87,17 @@ static int android_close(void *cookie);
// Module Functions Definition - Utilities
//----------------------------------------------------------------------------------
// Enable trace log message types (bit flags based)
void SetTraceLogTypes(unsigned char types)
{
logTypeFlags = types;
}
// Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
void TraceLog(int msgType, const char *text, ...)
{
#if defined(SUPPORT_TRACELOG)
static char buffer[128];
int traceDebugMsgs = 0;
#if defined(SUPPORT_TRACELOG_DEBUG)
traceDebugMsgs = 1;
#endif
switch(msgType)
{
@ -116,14 +117,21 @@ void TraceLog(int msgType, const char *text, ...)
#if defined(PLATFORM_ANDROID)
switch(msgType)
{
case LOG_INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break;
case LOG_ERROR: __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break;
case LOG_WARNING: __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break;
case LOG_DEBUG: if (traceDebugMsgs) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break;
case LOG_INFO: k">if (logTypeFlags & LOG_INFO) __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break;
case LOG_WARNING: if (logTypeFlags & LOG_WARNING) __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break;
case LOG_ERROR: if (logTypeFlags & LOG_ERROR) __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break;
case LOG_DEBUG: if (logTypeFlags & LOG_DEBUG) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break;
default: break;
}
#else
if ((msgType != LOG_DEBUG) || ((msgType == LOG_DEBUG) && (traceDebugMsgs))) vprintf(buffer, args);
switch(msgType)
{
case LOG_INFO: if (logTypeFlags & LOG_INFO) vprintf(buffer, args); break;
case LOG_WARNING: if (logTypeFlags & LOG_WARNING) vprintf(buffer, args); break;
case LOG_ERROR: if (logTypeFlags & LOG_ERROR) vprintf(buffer, args); break;
case LOG_DEBUG: if (logTypeFlags & LOG_DEBUG) vprintf(buffer, args); break;
default: break;
}
#endif
va_end(args);

Loading…
Cancel
Save