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;
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;
16 s_MsgPrefix[MSG_LOG] =
"Log";
17 s_MsgPrefix[MSG_WARNING] =
"Warning";
18 s_MsgPrefix[MSG_ERROR] =
"Error";
20 s_MsgStackMarkStart =
"-- Stack trace --";
21 s_MsgStackMarked =
false;
22 s_MsgStackMarkEnd =
"-----------------";
24 s_TraceAllLogs =
false;
37 static void Log(
string msg)
39 LogMessage(msg, MSG_LOG, s_TraceAllLogs);
56 static void LogAndTrace(
string msg)
58 LogMessage(msg, MSG_LOG,
true);
71 static void LogWarning(
string msg)
73 LogMessage(msg, MSG_WARNING, s_TraceAllLogs);
90 static void LogWarningAndTrace(
string msg)
92 LogMessage(msg, MSG_WARNING,
true);
105 static void LogError(
string msg)
107 LogMessage(msg, MSG_ERROR, s_TraceAllLogs);
124 static void LogErrorAndTrace(
string msg)
126 LogMessage(msg, MSG_ERROR,
true);
141 static string AdjustDebugLog(
string msg)
143 if ( IsStackTrace(msg) )
145 return TrimStackTrace(msg);
148 if ( IsDebugLog(msg) )
150 return TrimDebugLog(msg);
156 static void EnableTracingLogs(
bool enable)
158 s_TraceAllLogs = enable;
161 static private bool IsDebugLog(
string msg)
163 for (
int i = 0; i < MSG_COUNT; ++i )
165 if ( msg.IndexOf(s_MsgPrefix[i]) != -1 )
173 static private string TrimDebugLog(
string msg)
175 int msg_lenght = msg.Length();
176 int log_start = msg.IndexOf(
"'") + 1;
178 if ( log_start == -1 )
183 int log_lenght = msg_lenght - log_start - 2;
185 return msg.Substring(log_start, log_lenght);
187 static private bool IsStackTrace(
string msg)
189 if ( s_MsgStackMarked && msg.IndexOf(s_MsgStackMarkEnd) != -1 )
191 s_MsgStackMarked =
false;
195 if ( s_MsgStackMarked )
200 if ( msg.IndexOf(s_MsgStackMarkStart) != -1 )
202 s_MsgStackMarked =
true;
208 static private string TrimStackTrace(
string msg)
210 if ( msg.IndexOf(
"DebugPrint.c") != -1 )
218 static private void LogMessage(
string msg,
int msg_type,
bool trace=
false)
220 string mesg =
"["+s_MsgPrefix[msg_type]+
"]: "+msg;