Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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 {
92 LogMessage(msg, MSG_WARNING, true);
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 {
145 return TrimStackTrace(msg);
146 }
147
148 if ( IsDebugLog(msg) )
149 {
150 return TrimDebugLog(msg);
151 }
152
153 return msg;
154 }
155
156 static void EnableTracingLogs(bool enable)
157 {
158 s_TraceAllLogs = enable;
159 }
160
161 static private bool IsDebugLog(string msg)
162 {
163 for ( int i = 0; i < MSG_COUNT; ++i )
164 {
165 if ( msg.IndexOf(s_MsgPrefix[i]) != -1 )
166 {
167 return true;
168 }
169 }
170
171 return false;
172 }
173 static private string TrimDebugLog(string msg)
174 {
175 int msg_lenght = msg.Length();
176 int log_start = msg.IndexOf("'") + 1;
177
178 if ( log_start == -1 )
179 {
180 return msg;
181 }
182
183 int log_lenght = msg_lenght - log_start - 2;
184
185 return msg.Substring(log_start, log_lenght);
186 }
187 static private bool IsStackTrace(string msg)
188 {
189 if ( s_MsgStackMarked && msg.IndexOf(s_MsgStackMarkEnd) != -1 )
190 {
191 s_MsgStackMarked = false;
192 return false;
193 }
194
195 if ( s_MsgStackMarked )
196 {
197 return true;
198 }
199
200 if ( msg.IndexOf(s_MsgStackMarkStart) != -1 )
201 {
202 s_MsgStackMarked = true;
203 return true;
204 }
205
206 return false;
207 }
208 static private string TrimStackTrace(string msg)
209 {
210 if ( msg.IndexOf("DebugPrint.c") != -1 )
211 {
212 return string.Empty;
213 }
214
215 return msg;
216 }
217
218 static private void LogMessage(string msg, int msg_type, bool trace=false)
219 {
220 string mesg = "["+s_MsgPrefix[msg_type]+"]: "+msg;
221
222 Print(mesg);
223
224 if ( trace )
225 {
226 DumpStack();
227 }
228 }
229};
static void EnableTracingLogs(bool enable)
Definition debugprint.c:156
bool s_MsgStackMarked
Definition debugprint.c:11
bool IsStackTrace(string msg)
Definition debugprint.c:187
void LogMessage(string msg, int msg_type, bool trace=false)
Definition debugprint.c:218
static void LogWarningAndTrace(string msg)
Prints debug message as warning message and prints stack trace of calls.
Definition debugprint.c:90
string s_MsgPrefix[MSG_COUNT]
Definition debugprint.c:8
string s_MsgStackMarkEnd
Definition debugprint.c:10
static void LogWarning(string msg)
Prints debug message as warning message.
Definition debugprint.c:71
const int MSG_WARNING
Definition debugprint.c:4
const int MSG_LOG
Definition debugprint.c:3
static void LogError(string msg)
Prints debug message as error message.
Definition debugprint.c:105
const int MSG_ERROR
Definition debugprint.c:5
static string AdjustDebugLog(string msg)
Function adjust received message for debug console (Do not use).
Definition debugprint.c:141
string s_MsgStackMarkStart
Definition debugprint.c:9
static void Log(string msg)
Prints debug message with normal prio.
Definition debugprint.c:37
bool IsDebugLog(string msg)
Definition debugprint.c:161
static void OnInit()
Definition debugprint.c:14
string TrimDebugLog(string msg)
Definition debugprint.c:173
bool s_TraceAllLogs
Definition debugprint.c:12
static void LogAndTrace(string msg)
Prints debug message as normal message and prints stack trace of calls.
Definition debugprint.c:56
static void LogErrorAndTrace(string msg)
Prints debug message as error message and prints stack trace of calls.
Definition debugprint.c:124
string TrimStackTrace(string msg)
Definition debugprint.c:208
const int MSG_COUNT
Definition debugprint.c:6
proto void DumpStack()
Prints current call stack (stack trace).
proto void Print(void var)
Prints content of variable to console/log.
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
proto native int IndexOf(string sample)
Finds 'sample' in 'str'.
proto native int Length()
Returns length of string.