CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/Log.h
Views: 1401
1
// Copyright (C) 2003 Dolphin Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official SVN repository and contact information can be found at
16
// http://code.google.com/p/dolphin-emu/
17
18
#pragma once
19
20
#include "CommonFuncs.h"
21
22
#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and debugprintfs from the game itself.
23
#define ERROR_LEVEL 2 // Important errors.
24
#define WARNING_LEVEL 3 // Something is suspicious.
25
#define INFO_LEVEL 4 // General information.
26
#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.
27
#define VERBOSE_LEVEL 6 // Noisy debugging - sometimes needed but usually unimportant.
28
29
// NOTE: Needs to be kept in sync with the g_logTypeNames array.
30
enum class Log {
31
System = 0, // Catch-all for uncategorized things
32
Boot,
33
Common,
34
CPU,
35
FileSystem,
36
G3D,
37
HLE, // dumping ground that we should get rid of
38
JIT,
39
Loader,
40
ME,
41
MemMap,
42
SasMix,
43
SaveState,
44
FrameBuf,
45
Audio,
46
IO,
47
Achievements,
48
HTTP,
49
Printf,
50
51
sceAudio,
52
sceCtrl,
53
sceDisplay,
54
sceFont,
55
sceGe,
56
sceIntc,
57
sceIo,
58
sceKernel,
59
sceModule,
60
sceNet,
61
sceRtc,
62
sceSas,
63
sceUtility,
64
sceMisc,
65
66
NUMBER_OF_LOGS, // Must be last
67
};
68
69
enum class LogLevel : int {
70
LNOTICE = NOTICE_LEVEL,
71
LERROR = ERROR_LEVEL,
72
LWARNING = WARNING_LEVEL,
73
LINFO = INFO_LEVEL,
74
LDEBUG = DEBUG_LEVEL,
75
LVERBOSE = VERBOSE_LEVEL,
76
};
77
78
void GenericLog(LogLevel level, Log type, const char *file, int line, const char *fmt, ...)
79
#ifdef __GNUC__
80
__attribute__((format(printf, 5, 6)))
81
#endif
82
;
83
bool GenericLogEnabled(LogLevel level, Log type);
84
85
// Exception for Windows - enable more log levels in release mode than on other platforms.
86
#if defined(_DEBUG) || defined(_WIN32)
87
88
// Needs to be an int (and not use the enum) because it's used by the preprocessor!
89
#define MAX_LOGLEVEL DEBUG_LEVEL
90
91
#else
92
93
#ifndef MAX_LOGLEVEL
94
#define MAX_LOGLEVEL INFO_LEVEL
95
#endif // loglevel
96
97
#endif // logging
98
99
// Let the compiler optimize this out.
100
// TODO: Compute a dynamic max level as well that can be checked here.
101
#define GENERIC_LOG(t, v, ...) { \
102
if ((int)v <= MAX_LOGLEVEL) \
103
GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
104
}
105
106
#define ERROR_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LERROR, __VA_ARGS__) } while (false)
107
#define WARN_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LWARNING, __VA_ARGS__) } while (false)
108
#define NOTICE_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LNOTICE, __VA_ARGS__) } while (false)
109
#define INFO_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LINFO, __VA_ARGS__) } while (false)
110
#define DEBUG_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LDEBUG, __VA_ARGS__) } while (false)
111
#define VERBOSE_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LVERBOSE, __VA_ARGS__) } while (false)
112
113
// Currently only actually shows a dialog box on Windows.
114
bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...)
115
#ifdef __GNUC__
116
__attribute__((format(printf, 5, 6)))
117
#endif
118
;
119
120
bool HitAnyAsserts();
121
void ResetHitAnyAsserts();
122
void SetExtraAssertInfo(const char *info);
123
void SetCleanExitOnAssert();
124
125
#if defined(__ANDROID__)
126
// Tricky macro to get the basename, that also works if *built* on Win32.
127
// Doesn't mean this macro can be used on Win32 though.
128
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__))
129
#else
130
#define __FILENAME__ __FILE__
131
#endif
132
133
// If we're a debug build, _dbg_assert_ is active. Not otherwise, even on Windows.
134
#if defined(_DEBUG)
135
136
#define _dbg_assert_(_a_) \
137
if (!(_a_)) {\
138
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
139
}
140
141
#define _dbg_assert_msg_(_a_, ...) \
142
if (!(_a_)) { \
143
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
144
}
145
146
#else // not debug
147
148
#ifndef _dbg_assert_
149
#define _dbg_assert_(_a_) {}
150
#define _dbg_assert_msg_(_a_, _desc_, ...) {}
151
#endif // dbg_assert
152
153
#endif // MAX_LOGLEVEL DEBUG
154
155
#define _assert_(_a_) \
156
if (!(_a_)) {\
157
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
158
}
159
160
#define _assert_msg_(_a_, ...) \
161
if (!(_a_)) { \
162
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
163
}
164
165
// Just INFO_LOGs on nonWindows. On Windows it outputs to the VS output console.
166
void OutputDebugStringUTF8(const char *p);
167
168