Merge pull request #731 from MarcoLizza/reorganizing-logging
Reorganizing logging
This commit is contained in:
commit
9b97cf6972
11
src/raudio.c
11
src/raudio.c
@ -166,11 +166,14 @@ typedef struct MusicData {
|
||||
|
||||
#if defined(RAUDIO_STANDALONE)
|
||||
typedef enum {
|
||||
LOG_INFO = 0,
|
||||
LOG_ERROR,
|
||||
LOG_WARNING,
|
||||
LOG_ALL,
|
||||
LOG_TRACE,
|
||||
LOG_DEBUG,
|
||||
LOG_OTHER
|
||||
LOG_INFO,
|
||||
LOG_WARNING,
|
||||
LOG_ERROR,
|
||||
LOG_FATAL,
|
||||
LOG_NONE
|
||||
} TraceLogType;
|
||||
#endif
|
||||
|
||||
|
21
src/raylib.h
21
src/raylib.h
@ -422,13 +422,15 @@ typedef enum {
|
||||
} ConfigFlag;
|
||||
|
||||
// Trace log type
|
||||
// NOTE: Used for bit masks
|
||||
typedef enum {
|
||||
LOG_INFO = 1,
|
||||
LOG_WARNING = 2,
|
||||
LOG_ERROR = 4,
|
||||
LOG_DEBUG = 8,
|
||||
LOG_OTHER = 16
|
||||
LOG_ALL, // Display all logs
|
||||
LOG_TRACE,
|
||||
LOG_DEBUG,
|
||||
LOG_INFO,
|
||||
LOG_WARNING,
|
||||
LOG_ERROR,
|
||||
LOG_FATAL,
|
||||
LOG_NONE // Disable logging
|
||||
} TraceLogType;
|
||||
|
||||
// Keyboard keys
|
||||
@ -818,7 +820,7 @@ typedef enum {
|
||||
} NPatchType;
|
||||
|
||||
// Callbacks to be implemented by users
|
||||
typedef void (*TraceLogCallback)(int msgType, const char *text, va_list args);
|
||||
typedef void (*TraceLogCallback)(int logType, const char *text, va_list args);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
@ -898,9 +900,10 @@ RLAPI Color Fade(Color color, float alpha); // Color fade-
|
||||
|
||||
// Misc. functions
|
||||
RLAPI void SetConfigFlags(unsigned char flags); // Setup window configuration flags (view FLAGS)
|
||||
RLAPI void SetTraceLog(unsigned char types); // Enable trace log message types (bit flags based)
|
||||
RLAPI void SetTraceLogLevel(int logType); // Set the current threshold (minimum) log level.
|
||||
RLAPI void SetTraceLogExit(int logType); // Set the exit threshold (minimum) log level.
|
||||
RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set a trace log callback to enable custom logging bypassing raylib's one
|
||||
RLAPI void TraceLog(int logType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
|
||||
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)
|
||||
|
||||
|
11
src/rlgl.h
11
src/rlgl.h
@ -253,11 +253,14 @@ typedef unsigned char byte;
|
||||
|
||||
// TraceLog message types
|
||||
typedef enum {
|
||||
LOG_INFO = 0,
|
||||
LOG_ERROR,
|
||||
LOG_WARNING,
|
||||
LOG_ALL,
|
||||
LOG_TRACE,
|
||||
LOG_DEBUG,
|
||||
LOG_OTHER
|
||||
LOG_INFO,
|
||||
LOG_WARNING,
|
||||
LOG_ERROR,
|
||||
LOG_FATAL,
|
||||
LOG_NONE
|
||||
} TraceLogType;
|
||||
|
||||
// Texture formats (support depends on OpenGL version)
|
||||
|
75
src/utils.c
75
src/utils.c
@ -52,8 +52,9 @@
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Log types messages supported flags (bit based)
|
||||
static unsigned char logTypeFlags = LOG_INFO | LOG_WARNING | LOG_ERROR;
|
||||
// Log types messages
|
||||
static int logTypeLevel = LOG_INFO;
|
||||
static int logTypeExit = LOG_ERROR;
|
||||
static TraceLogCallback logCallback = NULL;
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
@ -79,10 +80,16 @@ static int android_close(void *cookie);
|
||||
// Module Functions Definition - Utilities
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Enable trace log message types (bit flags based)
|
||||
void SetTraceLog(unsigned char types)
|
||||
// Set the current threshold (minimum) log level.
|
||||
void SetTraceLogLevel(int logType)
|
||||
{
|
||||
logTypeFlags = types;
|
||||
logTypeLevel = logType;
|
||||
}
|
||||
|
||||
// Set the exit threshold (minimum) log level.
|
||||
void SetTraceLogExit(int logType)
|
||||
{
|
||||
logTypeExit = logType;
|
||||
}
|
||||
|
||||
// Set a trace log callback to enable custom logging bypassing raylib's one
|
||||
@ -92,58 +99,56 @@ void SetTraceLogCallback(TraceLogCallback callback)
|
||||
}
|
||||
|
||||
// Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
|
||||
void TraceLog(int msgType, const char *text, ...)
|
||||
void TraceLog(int logType, const char *text, ...)
|
||||
{
|
||||
#if defined(SUPPORT_TRACELOG)
|
||||
char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 };
|
||||
if (logType < logTypeLevel) { // Message has level below current threshold, don't emit.
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
|
||||
if (logCallback)
|
||||
{
|
||||
logCallback(msgType, text, args);
|
||||
logCallback(logType, text, args);
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(msgType)
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
switch(logType)
|
||||
{
|
||||
case LOG_INFO: strcpy(buffer, "INFO: "); break;
|
||||
case LOG_ERROR: strcpy(buffer, "ERROR: "); break;
|
||||
case LOG_WARNING: strcpy(buffer, "WARNING: "); break;
|
||||
case LOG_TRACE: __android_log_vprint(ANDROID_LOG_VERBOSE, "raylib", text, args); break;
|
||||
case LOG_DEBUG: __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", text, args); break;
|
||||
case LOG_INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", text, args); ; break;
|
||||
case LOG_WARNING: __android_log_vprint(ANDROID_LOG_WARN, "raylib", text, args); break;
|
||||
case LOG_ERROR: __android_log_vprint(ANDROID_LOG_ERROR, "raylib", text, args); break;
|
||||
case LOG_FATAL: __android_log_vprint(ANDROID_LOG_FATAL, "raylib", text, args); break;
|
||||
default: break;
|
||||
}
|
||||
#else
|
||||
char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 };
|
||||
|
||||
switch(logType)
|
||||
{
|
||||
case LOG_TRACE: strcpy(buffer, "TRACE: "); break;
|
||||
case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break;
|
||||
case LOG_OTHER: strcpy(buffer, "OTHER: "); break;
|
||||
case LOG_INFO: strcpy(buffer, "INFO: "); ; break;
|
||||
case LOG_WARNING: strcpy(buffer, "WARN: "); break;
|
||||
case LOG_ERROR: strcpy(buffer, "ERROR: "); break;
|
||||
case LOG_FATAL: strcpy(buffer, "FATAL: "); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
strcat(buffer, text);
|
||||
strcat(buffer, "\n");
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
switch(msgType)
|
||||
{
|
||||
case LOG_INFO: 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;
|
||||
case LOG_OTHER: if (logTypeFlags & LOG_OTHER) __android_log_vprint(ANDROID_LOG_VERBOSE, "raylib", buffer, args); break;
|
||||
default: break;
|
||||
}
|
||||
#else
|
||||
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;
|
||||
case LOG_OTHER: if (logTypeFlags & LOG_OTHER) vprintf(buffer, args); break;
|
||||
default: break;
|
||||
}
|
||||
vprintf(buffer, args);
|
||||
#endif
|
||||
|
||||
va_end(args);
|
||||
|
||||
if (msgType == LOG_ERROR) exit(1); // If LOG_ERROR message, exit program
|
||||
if (logType >= logTypeExit) exit(1); // If exit message, exit program
|
||||
|
||||
#endif // SUPPORT_TRACELOG
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user