DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
DebugPrint.c
См. документацию.
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};
bool s_MsgStackMarked
Определения DebugPrint.c:11
string s_MsgStackMarkEnd
Определения DebugPrint.c:10
bool s_TraceAllLogs
Определения DebugPrint.c:12
static void Log(string msg)
Prints debug message with normal prio.
Определения DebugPrint.c:37
static void LogWarningAndTrace(string msg)
Prints debug message as warning message and prints stack trace of calls.
Определения DebugPrint.c:90
const int MSG_LOG
Определения DebugPrint.c:3
static void LogError(string msg)
Prints debug message as error message.
Определения DebugPrint.c:105
string s_MsgPrefix[MSG_COUNT]
Определения DebugPrint.c:8
bool IsStackTrace(string msg)
Определения DebugPrint.c:187
bool IsDebugLog(string msg)
Определения DebugPrint.c:161
static void LogAndTrace(string msg)
Prints debug message as normal message and prints stack trace of calls.
Определения DebugPrint.c:56
static void EnableTracingLogs(bool enable)
Определения DebugPrint.c:156
static void LogWarning(string msg)
Prints debug message as warning message.
Определения DebugPrint.c:71
static void OnInit()
Определения DebugPrint.c:14
string TrimStackTrace(string msg)
Определения DebugPrint.c:208
string TrimDebugLog(string msg)
Определения DebugPrint.c:173
static void LogErrorAndTrace(string msg)
Prints debug message as error message and prints stack trace of calls.
Определения DebugPrint.c:124
string s_MsgStackMarkStart
Определения DebugPrint.c:9
const int MSG_WARNING
Определения DebugPrint.c:4
static string AdjustDebugLog(string msg)
Function adjust received message for debug console (Do not use)
Определения DebugPrint.c:141
const int MSG_ERROR
Определения DebugPrint.c:5
const int MSG_COUNT
Определения DebugPrint.c:6
void LogMessage(string msg, int msg_type, bool trace=false)
Определения DebugPrint.c:218
Определения DebugPrint.c:2
proto void DumpStack()
Prints current call stack (stack trace)
proto void Print(void var)
Prints content of variable to console/log.
proto native int Length()
Returns length of string.
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'. Returns -1 when not found.