forked from sergiou87/open-supaplex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.c
90 lines (73 loc) · 1.93 KB
/
logging.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* This file is part of the OpenSupaplex distribution (https://github.com/sergiou87/open-supaplex).
* Copyright (c) 2020 Sergio Padrino
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "logging.h"
#if HAVE_SDL2
#include <SDL2/SDL.h>
#endif
#if (defined(__vita__) || defined(__PSL1GHT__)) && DEBUG
#define USE_DEBUGNET 1
#endif
#if USE_DEBUGNET
#include <debugnet.h>
#endif
#if defined(__SWITCH__) && DEBUG
#include <switch.h>
#endif
LogLevel gLogLevel = LogLevelInfo;
void setLogLevel(LogLevel logLevel)
{
gLogLevel = logLevel;
}
void initializeLogging(void)
{
#if USE_DEBUGNET
debugNetInit(DEBUGNETIP, 18194, DEBUG);
#endif
#if defined(__SWITCH__) && DEBUG
socketInitializeDefault(); // Initialize sockets
nxlinkStdio(); // Redirect stdout and stderr over the network to nxlink
#endif
spLogInfo("Logging system initialized.");
}
void destroyLogging(void)
{
spLogInfo("Destroying logging system...");
#if defined(__SWITCH__) && DEBUG
socketExit();
#endif
spLogInfo("Logging system destroyed");
}
void spLog(LogLevel level, const char *format, ...)
{
char buffer[0x800];
if (gLogLevel > level)
{
return;
}
va_list argptr;
va_start(argptr, format);
vsprintf(buffer, format, argptr);
va_end(argptr);
#if USE_DEBUGNET
debugNetPrintf(INFO, "%s\n", buffer);
#endif
#if HAVE_SDL2
SDL_Log("%s", buffer);
#else
printf("%s\n", buffer);
#endif
}