|
@@ -1,18 +1,19 @@
|
|
|
/*
|
|
|
- * 2D Game Engine
|
|
|
- * Logger.cpp:
|
|
|
- * Based on pikuma.com 2D game engine in C++ and Lua course
|
|
|
- * Copyright (c) 2021 986-Studio. All rights reserved.
|
|
|
+ * 2D Physic Engine
|
|
|
+ * logger.cpp: The logger
|
|
|
+ * Based on pikuma.com Learn Game Physics Engine Programming course.
|
|
|
+ * Copyright (c) 2021-2022 986-Studio. All rights reserved.
|
|
|
*
|
|
|
* Created by Manoël Trapier on 11/02/2021.
|
|
|
*/
|
|
|
+
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <stdint.h>
|
|
|
#include <stdarg.h>
|
|
|
#include <time.h>
|
|
|
|
|
|
-#include <Logger.h>
|
|
|
+#include <logger.h>
|
|
|
|
|
|
typedef struct logData
|
|
|
{
|
|
@@ -30,37 +31,21 @@ static logData dataTable[] =
|
|
|
[LOG_DEBUG] = { "DEBUG", 35 },
|
|
|
};
|
|
|
|
|
|
-std::vector<LogEntry> Logger::messages;
|
|
|
-
|
|
|
-static void printLastLog()
|
|
|
+static void addLog(LogType type, const char *message, va_list params)
|
|
|
{
|
|
|
- LogEntry entry = Logger::messages.back();
|
|
|
+ time_t curtime = time(NULL);
|
|
|
|
|
|
char buf[30];
|
|
|
- struct tm *p = localtime(&entry.timestamp);
|
|
|
- int typeColour = dataTable[entry.type].colour;
|
|
|
- const char *typeName = dataTable[entry.type].name;
|
|
|
+ struct tm *p = localtime(&curtime);
|
|
|
+ int typeColour = dataTable[type].colour;
|
|
|
+ const char *typeName = dataTable[type].name;
|
|
|
|
|
|
strftime(buf, 38, "%d-%b-%Y %H:%M:%S", p);
|
|
|
fprintf(stderr, "\x1B[%d;1m%-6s | %-20s - ", typeColour, typeName, buf);
|
|
|
- fprintf(stderr, "%s", entry.message);
|
|
|
+ vfprintf(stderr, message, params);
|
|
|
fprintf(stderr, "\x1B[0m\n");
|
|
|
}
|
|
|
|
|
|
-static void addLog(LogType type, const char *message, va_list params)
|
|
|
-{
|
|
|
- LogEntry entry;
|
|
|
- time_t curtime = time(NULL);
|
|
|
-
|
|
|
- entry.message = (char *)calloc(512, sizeof(char));
|
|
|
- vsnprintf(entry.message, 510, message, params);
|
|
|
- entry.timestamp = curtime;
|
|
|
- entry.type = type;
|
|
|
-
|
|
|
- Logger::messages.push_back(entry);
|
|
|
- printLastLog();
|
|
|
-}
|
|
|
-
|
|
|
void Logger::Log(const char *message, ...)
|
|
|
{
|
|
|
va_list list;
|