Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions examples/core/core_custom_logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,33 @@
*
********************************************************************************************/

#include "raylib.h"
#include "../src/raylib.h"

#include <stdio.h> // Required for: fopen(), fclose(), fputc(), fwrite(), printf(), fprintf(), funopen()
#include <time.h> // Required for: time_t, tm, time(), localtime(), strftime()

// Custom logging function
void CustomLog(int msgType, const char *text, va_list args)
{

char timeStr[64] = { 0 };
time_t now = time(NULL);
struct tm *tm_info = localtime(&now);

strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info);
printf("[%s] ", timeStr);

switch (msgType)
{
case LOG_INFO: printf("[INFO] : "); break;
case LOG_ERROR: printf("[ERROR]: "); break;
case LOG_WARNING: printf("[WARN] : "); break;
case LOG_DEBUG: printf("[DEBUG]: "); break;
case LOG_INFO: printf(ANSI_GREEN "[%s] [INFO] : ", timeStr); break;
case LOG_ERROR: printf(ANSI_YELLOW "[%s] [ERROR]: ", timeStr); break;
case LOG_WARNING: printf(ANSI_RED "[%s] [WARN] : ", timeStr); break;
case LOG_DEBUG: printf(ANSI_BLUE "[%s] [DEBUG]: ", timeStr); break;
case LOG_FATAL: printf(ANSI_BOLD ANSI_RED "[%s] [FATAL] : ", timeStr); break;
default: break;
}

printf("%s", ANSI_RESET);

vprintf(text, args);
printf("\n");
}
Expand Down
11 changes: 11 additions & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,17 @@ typedef enum {
LOG_NONE // Disable logging
} TraceLogLevel;

// ANSI Colors
#define ANSI_RESET "\x1b[0m"
#define ANSI_RED "\x1b[31m"
#define ANSI_GREEN "\x1b[32m"
#define ANSI_YELLOW "\x1b[33m"
#define ANSI_BLUE "\x1b[34m"
#define ANSI_MAGENTA "\x1b[35m"
#define ANSI_CYAN "\x1b[36m"
#define ANSI_WHITE "\x1b[37m"
#define ANSI_BOLD "\x1b[1m"

// Keyboard keys (US keyboard layout)
// NOTE: Use GetKeyPressed() to allow redefining
// required keys for alternative layouts
Expand Down
14 changes: 8 additions & 6 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ void TraceLog(int logType, const char *text, ...)

switch (logType)
{
case LOG_TRACE: strcpy(buffer, "TRACE: "); break;
case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break;
case LOG_INFO: strcpy(buffer, "INFO: "); break;
case LOG_WARNING: strcpy(buffer, "WARNING: "); break;
case LOG_ERROR: strcpy(buffer, "ERROR: "); break;
case LOG_FATAL: strcpy(buffer, "FATAL: "); break;
case LOG_TRACE: printf(ANSI_BLUE "TRACE: "); break;
case LOG_DEBUG: printf(ANSI_CYAN "DEBUG: "); break;
case LOG_INFO: printf(ANSI_GREEN "INFO: "); break;
case LOG_WARNING: printf(ANSI_YELLOW "WARNING: "); break;
case LOG_ERROR: printf(ANSI_RED "ERROR: "); break;
case LOG_FATAL: printf(ANSI_BOLD ANSI_RED "FATAL: "); break;
default: break;
}

printf("%s", ANSI_RESET);

unsigned int textSize = (unsigned int)strlen(text);
memcpy(buffer + strlen(buffer), text, (textSize < (MAX_TRACELOG_MSG_LENGTH - 12))? textSize : (MAX_TRACELOG_MSG_LENGTH - 12));
strcat(buffer, "\n");
Expand Down