aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/LogBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Console/LogBase.cs')
-rw-r--r--OpenSim/Framework/Console/LogBase.cs121
1 files changed, 57 insertions, 64 deletions
diff --git a/OpenSim/Framework/Console/LogBase.cs b/OpenSim/Framework/Console/LogBase.cs
index 67440f6..5a7ce4d 100644
--- a/OpenSim/Framework/Console/LogBase.cs
+++ b/OpenSim/Framework/Console/LogBase.cs
@@ -46,6 +46,8 @@ namespace OpenSim.Framework.Console
46 46
47 public class LogBase 47 public class LogBase
48 { 48 {
49 private object m_syncRoot = new object();
50
49 StreamWriter Log; 51 StreamWriter Log;
50 public conscmd_callback cmdparser; 52 public conscmd_callback cmdparser;
51 public string componentname; 53 public string componentname;
@@ -64,7 +66,7 @@ namespace OpenSim.Framework.Console
64 } 66 }
65 67
66 System.Console.WriteLine("Logs will be saved to current directory in " + LogFile); 68 System.Console.WriteLine("Logs will be saved to current directory in " + LogFile);
67 69
68 Log = File.AppendText(LogFile); 70 Log = File.AppendText(LogFile);
69 Log.WriteLine("========================================================================"); 71 Log.WriteLine("========================================================================");
70 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString()); 72 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString());
@@ -76,27 +78,6 @@ namespace OpenSim.Framework.Console
76 Log.Close(); 78 Log.Close();
77 } 79 }
78 80
79 [Obsolete("Log.WriteLine is obsolete, use Warn / Error / Verbose instead.")]
80 public void Write(string format, params object[] args)
81 {
82 // HOUSEKEEPING : Will remove once use is removed.
83 Notice(format, args);
84 return;
85 }
86
87 [Obsolete("Log.WriteLine is obsolete, use Warn / Error / Verbose instead.")]
88 public void WriteLine(LogPriority importance, string format, params object[] args)
89 {
90 // HOUSEKEEPING : Will remove once use is removed.
91 Log.WriteLine(format, args);
92 Log.Flush();
93 if (!m_silent)
94 {
95 System.Console.WriteLine(format, args);
96 }
97 return;
98 }
99
100 /// <summary> 81 /// <summary>
101 /// derive an ansi color from a string, ignoring the darker colors. 82 /// derive an ansi color from a string, ignoring the darker colors.
102 /// This is used to help automatically bin component tags with colors 83 /// This is used to help automatically bin component tags with colors
@@ -178,7 +159,7 @@ namespace OpenSim.Framework.Console
178 public void Error(string sender, string format, params object[] args) 159 public void Error(string sender, string format, params object[] args)
179 { 160 {
180 WritePrefixLine(DeriveColor(sender), sender); 161 WritePrefixLine(DeriveColor(sender), sender);
181 Error( format, args); 162 Error(format, args);
182 return; 163 return;
183 } 164 }
184 165
@@ -229,7 +210,7 @@ namespace OpenSim.Framework.Console
229 WriteNewLine(ConsoleColor.Blue, format, args); 210 WriteNewLine(ConsoleColor.Blue, format, args);
230 return; 211 return;
231 } 212 }
232 213
233 [Conditional("DEBUG")] 214 [Conditional("DEBUG")]
234 public void Debug(string format, params object[] args) 215 public void Debug(string format, params object[] args)
235 { 216 {
@@ -247,66 +228,75 @@ namespace OpenSim.Framework.Console
247 228
248 private void WriteNewLine(ConsoleColor color, string format, params object[] args) 229 private void WriteNewLine(ConsoleColor color, string format, params object[] args)
249 { 230 {
250 string now = System.DateTime.Now.ToString("[MM-dd hh:mm:ss] "); 231 lock (m_syncRoot)
251 Log.Write(now);
252 Log.WriteLine(format, args);
253 Log.Flush();
254 if (!m_silent)
255 { 232 {
256 System.Console.Write(now); 233 string now = System.DateTime.Now.ToString("[MM-dd hh:mm:ss] ");
257 try 234 Log.Write(now);
235 Log.WriteLine(format, args);
236 Log.Flush();
237 if (!m_silent)
258 { 238 {
259 if (color != ConsoleColor.White) 239 System.Console.Write(now);
260 System.Console.ForegroundColor = color; 240 try
241 {
242 if (color != ConsoleColor.White)
243 System.Console.ForegroundColor = color;
261 244
262 System.Console.WriteLine(format, args); 245 System.Console.WriteLine(format, args);
263 System.Console.ResetColor(); 246 System.Console.ResetColor();
264 } 247 }
265 catch (ArgumentNullException) 248 catch (ArgumentNullException)
266 { 249 {
267 // Some older systems dont support coloured text. 250 // Some older systems dont support coloured text.
268 System.Console.WriteLine(format, args); 251 System.Console.WriteLine(format, args);
252 }
269 } 253 }
254 return;
270 } 255 }
271 return;
272 } 256 }
273 257
274 private void WritePrefixLine(ConsoleColor color, string sender) 258 private void WritePrefixLine(ConsoleColor color, string sender)
275 { 259 {
276 sender = sender.ToUpper(); 260 lock (m_syncRoot)
277 Log.WriteLine("[" + sender + "] "); 261 {
278 Log.Flush(); 262 sender = sender.ToUpper();
263 Log.WriteLine("[" + sender + "] ");
264 Log.Flush();
279 265
280 System.Console.Write("["); 266 System.Console.Write("[");
281 267
282 if (!m_silent) 268 if (!m_silent)
283 {
284 try
285 {
286 System.Console.ForegroundColor = color;
287 System.Console.Write(sender);
288 System.Console.ResetColor();
289 }
290 catch (ArgumentNullException)
291 { 269 {
292 // Some older systems dont support coloured text. 270 try
293 System.Console.WriteLine(sender); 271 {
272 System.Console.ForegroundColor = color;
273 System.Console.Write(sender);
274 System.Console.ResetColor();
275 }
276 catch (ArgumentNullException)
277 {
278 // Some older systems dont support coloured text.
279 System.Console.WriteLine(sender);
280 }
294 } 281 }
295 }
296 282
297 System.Console.Write("] \t"); 283 System.Console.Write("] \t");
298 284
299 return; 285 return;
286 }
300 } 287 }
301 288
302 289
303 public string ReadLine() 290 public string ReadLine()
304 { 291 {
305 try { 292 try
293 {
306 string TempStr = System.Console.ReadLine(); 294 string TempStr = System.Console.ReadLine();
307 Log.WriteLine(TempStr); 295 Log.WriteLine(TempStr);
308 return TempStr; 296 return TempStr;
309 } catch (Exception e) { 297 }
298 catch (Exception e)
299 {
310 MainLog.Instance.Error("Console", "System.Console.ReadLine exception " + e.ToString()); 300 MainLog.Instance.Error("Console", "System.Console.ReadLine exception " + e.ToString());
311 return ""; 301 return "";
312 } 302 }
@@ -446,9 +436,12 @@ namespace OpenSim.Framework.Console
446 Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1); 436 Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1);
447 Array.Reverse(tempstrarray); 437 Array.Reverse(tempstrarray);
448 string[] cmdparams = (string[])tempstrarray; 438 string[] cmdparams = (string[])tempstrarray;
449 try { 439 try
440 {
450 RunCmd(cmd, cmdparams); 441 RunCmd(cmd, cmdparams);
451 } catch (Exception e) { 442 }
443 catch (Exception e)
444 {
452 MainLog.Instance.Error("Console", "Command failed with exception " + e.ToString()); 445 MainLog.Instance.Error("Console", "Command failed with exception " + e.ToString());
453 } 446 }
454 } 447 }
@@ -458,7 +451,7 @@ namespace OpenSim.Framework.Console
458 get 451 get
459 { 452 {
460 string result = String.Empty; 453 string result = String.Empty;
461 454
462 string stacktrace = Environment.StackTrace; 455 string stacktrace = Environment.StackTrace;
463 List<string> lines = new List<string>(stacktrace.Split(new string[] { "at " }, StringSplitOptions.None)); 456 List<string> lines = new List<string>(stacktrace.Split(new string[] { "at " }, StringSplitOptions.None));
464 457