DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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
static private const int MSG_COUNT
Definition DebugPrint.c:6
static private bool s_MsgStackMarked
Definition DebugPrint.c:11
static private string s_MsgStackMarkStart
Definition DebugPrint.c:9
static private string s_MsgPrefix[MSG_COUNT]
Definition DebugPrint.c:8
static private 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
static private string TrimStackTrace(string msg)
Definition DebugPrint.c:208
static private const int MSG_LOG
Definition DebugPrint.c:3
static void LogWarning(string msg)
Prints debug message as warning message.
Definition DebugPrint.c:71
static private const int MSG_WARNING
Definition DebugPrint.c:4
static void LogError(string msg)
Prints debug message as error message.
Definition DebugPrint.c:105
static string AdjustDebugLog(string msg)
Function adjust received message for debug console (Do not use)
Definition DebugPrint.c:141
static void Log(string msg)
Prints debug message with normal prio.
Definition DebugPrint.c:37
static private bool IsStackTrace(string msg)
Definition DebugPrint.c:187
static void OnInit()
Definition DebugPrint.c:14
static private bool IsDebugLog(string msg)
Definition DebugPrint.c:161
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
static private const int MSG_ERROR
Definition DebugPrint.c:5
static private string s_MsgStackMarkEnd
Definition DebugPrint.c:10
static private bool s_TraceAllLogs
Definition DebugPrint.c:12
static private string TrimDebugLog(string msg)
Definition DebugPrint.c:173
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'. Returns -1 when not found.
static const string Empty
Definition EnString.c:7
proto native int Length()
Returns length of string.