DayZ 1.24
Loading...
Searching...
No Matches
DebugPrint.c
Go to the documentation of this file.
2{
3 static private const int MSG_LOG = 0;
4 static private const int MSG_WARNING = 1;
5 static private const int MSG_ERROR = 2;
6 static private const int MSG_COUNT = 3;
7
8 static private string s_MsgPrefix[MSG_COUNT];
9 static private string s_MsgStackMarkStart;
10 static private string s_MsgStackMarkEnd;
11 static private bool s_MsgStackMarked;
12 static private bool s_TraceAllLogs;
13
14 static void OnInit()
15 {
16 s_MsgPrefix[MSG_LOG] = "Log";
17 s_MsgPrefix[MSG_WARNING] = "Warning";
18 s_MsgPrefix[MSG_ERROR] = "Error";
19
20 s_MsgStackMarkStart = "-- Stack trace --";
21 s_MsgStackMarked = false;
22 s_MsgStackMarkEnd = "-----------------";
23
24 s_TraceAllLogs = false;
25 }
26
37 static void Log(string msg)
38 {
40 }
41
56 static void LogAndTrace(string msg)
57 {
58 LogMessage(msg, MSG_LOG, true);
59 }
60
71 static void LogWarning(string msg)
72 {
74 }
75
90 static void LogWarningAndTrace(string msg)
91 {
93 }
94
105 static void LogError(string msg)
106 {
108 }
109
124 static void LogErrorAndTrace(string msg)
125 {
126 LogMessage(msg, MSG_ERROR, true);
127 }
128
141 static string AdjustDebugLog(string msg)
142 {
143 if (IsStackTrace(msg))
144 return TrimStackTrace(msg);
145
146 if (IsDebugLog(msg))
147 return TrimDebugLog(msg);
148
149 return msg;
150 }
151
152 static void EnableTracingLogs(bool enable)
153 {
155 }
156
157 static private bool IsDebugLog(string msg)
158 {
159 for (int i = 0; i < MSG_COUNT; ++i)
160 {
161 if (msg.IndexOf(s_MsgPrefix[i]) != -1)
162 return true;
163 }
164
165 return false;
166 }
167 static private string TrimDebugLog(string msg)
168 {
169 int msg_lenght = msg.Length();
170 int log_start = msg.IndexOf("'") + 1;
171
172 if (log_start == -1)
173 return msg;
174
175 int log_lenght = msg_lenght - log_start - 2;
176
177 return msg.Substring(log_start, log_lenght);
178 }
179 static private bool IsStackTrace(string msg)
180 {
181 if (s_MsgStackMarked && msg.IndexOf(s_MsgStackMarkEnd) != -1)
182 {
183 s_MsgStackMarked = false;
184 return false;
185 }
186
188 return true;
189
190 if (msg.IndexOf(s_MsgStackMarkStart) != -1)
191 {
192 s_MsgStackMarked = true;
193 return true;
194 }
195
196 return false;
197 }
198 static private string TrimStackTrace(string msg)
199 {
200 if (msg.IndexOf("DebugPrint.c") != -1)
201 return string.Empty;
202
203 return msg;
204 }
205
206 static private void LogMessage(string msg, int msg_type, bool trace = false)
207 {
208 string mesg = "[" + s_MsgPrefix[msg_type] + "]: " + msg;
209
210 Print(mesg);
211
212 if (trace)
213 DumpStack();
214 }
215};
bool s_MsgStackMarked
Definition DebugPrint.c:11
string s_MsgStackMarkEnd
Definition DebugPrint.c:10
bool s_TraceAllLogs
Definition DebugPrint.c:12
static void Log(string msg)
Prints debug message with normal prio.
Definition DebugPrint.c:37
static void LogWarningAndTrace(string msg)
Prints debug message as warning message and prints stack trace of calls.
Definition DebugPrint.c:90
const int MSG_LOG
Definition DebugPrint.c:3
static void LogError(string msg)
Prints debug message as error message.
Definition DebugPrint.c:105
string s_MsgPrefix[MSG_COUNT]
Definition DebugPrint.c:8
bool IsStackTrace(string msg)
Definition DebugPrint.c:179
bool IsDebugLog(string msg)
Definition DebugPrint.c:157
static void LogAndTrace(string msg)
Prints debug message as normal message and prints stack trace of calls.
Definition DebugPrint.c:56
static void EnableTracingLogs(bool enable)
Definition DebugPrint.c:152
static void LogWarning(string msg)
Prints debug message as warning message.
Definition DebugPrint.c:71
static void OnInit()
Definition DebugPrint.c:14
string TrimStackTrace(string msg)
Definition DebugPrint.c:198
string TrimDebugLog(string msg)
Definition DebugPrint.c:167
static void LogErrorAndTrace(string msg)
Prints debug message as error message and prints stack trace of calls.
Definition DebugPrint.c:124
string s_MsgStackMarkStart
Definition DebugPrint.c:9
const int MSG_WARNING
Definition DebugPrint.c:4
static string AdjustDebugLog(string msg)
Function adjust received message for debug console (Do not use)
Definition DebugPrint.c:141
const int MSG_ERROR
Definition DebugPrint.c:5
const int MSG_COUNT
Definition DebugPrint.c:6
void LogMessage(string msg, int msg_type, bool trace=false)
Definition DebugPrint.c:206
proto void DumpStack()
Prints current call stack (stack trace)
proto void Print(void var)
Prints content of variable to console/log.
static const string Empty
Definition EnString.c:7