forked from djoslin0/sm64ex-coop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebuglog.h
57 lines (49 loc) · 1.72 KB
/
debuglog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef DEBUGLOG_H
#define DEBUGLOG_H
#include <stdio.h>
#include <time.h>
#include "pc/network/network.h"
#include "pc/djui/djui_console.h"
static void _debuglog_print_timestamp(void) {
time_t ltime = time(NULL);
#if defined(_WIN32)
char* str = asctime(localtime(<ime));
#else
struct tm ltime2 = { 0 };
localtime_r(<ime, <ime2);
char* str = asctime(<ime2);
#endif
printf("%.*s", (int)strlen(str) - 1, str);
}
static void _debuglog_print_network_type(void) {
printf(" [%02d] ", (gNetworkPlayerLocal != NULL) ? gNetworkPlayerLocal->globalIndex : -1);
}
static void _debuglog_print_log_type(char* logType) {
printf("[%s] ", logType);
}
static void _debuglog_print_short_filename(char* filename) {
char* last = strrchr(filename, '/');
if (last != NULL) {
printf("%s: ", last + 1);
}
else {
printf("???: ");
}
}
static void _debuglog_print_log(char* logType, char* filename) {
_debuglog_print_timestamp();
_debuglog_print_network_type();
_debuglog_print_log_type(logType);
_debuglog_print_short_filename(filename);
}
#if defined(DISABLE_MODULE_LOG)
#define LOG_DEBUG(...)
#define LOG_INFO(...)
#define LOG_ERROR(...)
#else
#define LOG_DEBUG(...) (configDebugPrint ? ( _debuglog_print_log("DEBUG", __FILE__), printf(__VA_ARGS__), printf("\n") ) : 0)
#define LOG_INFO(...) (configDebugInfo ? ( _debuglog_print_log("INFO", __FILE__), printf(__VA_ARGS__), printf("\n") ) : 0)
#define LOG_ERROR(...) (configDebugError ? ( _debuglog_print_log("ERROR", __FILE__), printf(__VA_ARGS__), printf("\n") ) : 0)
#endif
#define LOG_CONSOLE(...) { snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, __VA_ARGS__), djui_console_message_create(gDjuiConsoleTmpBuffer); }
#endif