aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorSean Dague2008-02-06 20:32:37 +0000
committerSean Dague2008-02-06 20:32:37 +0000
commitb3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc (patch)
tree32758b8055f13daead9e4aa57bf84f657d25d887 /OpenSim
parentShortened console log messages. (diff)
downloadopensim-SC_OLD-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.zip
opensim-SC_OLD-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.tar.gz
opensim-SC_OLD-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.tar.bz2
opensim-SC_OLD-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.tar.xz
pass 1 on getting colors back to the console
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/OpenSimAppender.cs69
1 files changed, 69 insertions, 0 deletions
diff --git a/OpenSim/Framework/Console/OpenSimAppender.cs b/OpenSim/Framework/Console/OpenSimAppender.cs
new file mode 100644
index 0000000..58d27d0
--- /dev/null
+++ b/OpenSim/Framework/Console/OpenSimAppender.cs
@@ -0,0 +1,69 @@
1using System;
2using System.Text;
3using System.Text.RegularExpressions;
4using System.Globalization;
5
6using log4net.Core;
7using log4net.Layout;
8using log4net.Appender;
9using log4net.Util;
10
11namespace OpenSim.Framework.Console
12{
13 public class OpenSimAppender : AnsiColorTerminalAppender
14 {
15 override protected void Append(LoggingEvent le)
16 {
17 string loggingMessage = RenderLoggingEvent(le);
18 string regex = @"^(?<Front>.*)\[(?<Category>\w+)\](?<End>.*)";
19
20 Regex RE = new Regex(regex, RegexOptions.Multiline);
21 MatchCollection matches = RE.Matches(loggingMessage);
22 // Get some direct matches $1 $4 is a
23 if (matches.Count == 1)
24 {
25 System.Console.Write(matches[0].Groups["Front"].Value);
26 System.Console.Write("[");
27
28 WriteColorText(DeriveColor(matches[0].Groups["Category"].Value), matches[0].Groups["Category"].Value);
29 System.Console.Write("]");
30 System.Console.Write(matches[0].Groups["End"].Value);
31 }
32 else
33 {
34 System.Console.WriteLine(loggingMessage);
35 }
36 }
37
38 private void WriteColorText(ConsoleColor color, string sender)
39 {
40 try
41 {
42 lock (this)
43 {
44 try
45 {
46 System.Console.ForegroundColor = color;
47 System.Console.Write(sender);
48 System.Console.ResetColor();
49 }
50 catch (ArgumentNullException)
51 {
52 // Some older systems dont support coloured text.
53 System.Console.WriteLine(sender);
54 }
55 }
56 }
57 catch (ObjectDisposedException)
58 {
59 }
60 }
61
62 private ConsoleColor DeriveColor(string input)
63 {
64 int colIdx = (input.ToUpper().GetHashCode() % 6) + 9;
65 return (ConsoleColor) colIdx;
66 }
67
68 }
69} \ No newline at end of file