diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Console/OpenSimAppender.cs | 82 |
1 files changed, 9 insertions, 73 deletions
diff --git a/OpenSim/Framework/Console/OpenSimAppender.cs b/OpenSim/Framework/Console/OpenSimAppender.cs index 6193bac..400bd83 100644 --- a/OpenSim/Framework/Console/OpenSimAppender.cs +++ b/OpenSim/Framework/Console/OpenSimAppender.cs | |||
@@ -26,7 +26,6 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Text.RegularExpressions; | ||
30 | using log4net.Appender; | 29 | using log4net.Appender; |
31 | using log4net.Core; | 30 | using log4net.Core; |
32 | 31 | ||
@@ -45,62 +44,29 @@ namespace OpenSim.Framework.Console | |||
45 | set { m_console = value; } | 44 | set { m_console = value; } |
46 | } | 45 | } |
47 | 46 | ||
48 | private static readonly ConsoleColor[] Colors = { | ||
49 | // the dark colors don't seem to be visible on some black background terminals like putty :( | ||
50 | //ConsoleColor.DarkBlue, | ||
51 | //ConsoleColor.DarkGreen, | ||
52 | //ConsoleColor.DarkCyan, | ||
53 | //ConsoleColor.DarkMagenta, | ||
54 | //ConsoleColor.DarkYellow, | ||
55 | ConsoleColor.Gray, | ||
56 | //ConsoleColor.DarkGray, | ||
57 | ConsoleColor.Blue, | ||
58 | ConsoleColor.Green, | ||
59 | ConsoleColor.Cyan, | ||
60 | ConsoleColor.Magenta, | ||
61 | ConsoleColor.Yellow | ||
62 | }; | ||
63 | |||
64 | override protected void Append(LoggingEvent le) | 47 | override protected void Append(LoggingEvent le) |
65 | { | 48 | { |
66 | if (m_console != null) | 49 | if (m_console != null) |
67 | m_console.LockOutput(); | 50 | m_console.LockOutput(); |
68 | 51 | ||
52 | string loggingMessage = RenderLoggingEvent(le); | ||
53 | |||
69 | try | 54 | try |
70 | { | 55 | { |
71 | string loggingMessage = RenderLoggingEvent(le); | 56 | if (m_console != null) |
72 | |||
73 | string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)"; | ||
74 | |||
75 | Regex RE = new Regex(regex, RegexOptions.Multiline); | ||
76 | MatchCollection matches = RE.Matches(loggingMessage); | ||
77 | |||
78 | // Get some direct matches $1 $4 is a | ||
79 | if (matches.Count == 1) | ||
80 | { | 57 | { |
81 | System.Console.Write(matches[0].Groups["Front"].Value); | 58 | string level = "normal"; |
82 | System.Console.Write("["); | ||
83 | |||
84 | WriteColorText(DeriveColor(matches[0].Groups["Category"].Value), matches[0].Groups["Category"].Value); | ||
85 | System.Console.Write("]:"); | ||
86 | 59 | ||
87 | if (le.Level == Level.Error) | 60 | if (le.Level == Level.Error) |
88 | { | 61 | level = "error"; |
89 | WriteColorText(ConsoleColor.Red, matches[0].Groups["End"].Value); | ||
90 | } | ||
91 | else if (le.Level == Level.Warn) | 62 | else if (le.Level == Level.Warn) |
92 | { | 63 | level = "warn"; |
93 | WriteColorText(ConsoleColor.Yellow, matches[0].Groups["End"].Value); | 64 | |
94 | } | 65 | m_console.Output(loggingMessage, level); |
95 | else | ||
96 | { | ||
97 | System.Console.Write(matches[0].Groups["End"].Value); | ||
98 | } | ||
99 | System.Console.WriteLine(); | ||
100 | } | 66 | } |
101 | else | 67 | else |
102 | { | 68 | { |
103 | System.Console.Write(loggingMessage); | 69 | System.Console.WriteLine(loggingMessage); |
104 | } | 70 | } |
105 | } | 71 | } |
106 | catch (Exception e) | 72 | catch (Exception e) |
@@ -113,35 +79,5 @@ namespace OpenSim.Framework.Console | |||
113 | m_console.UnlockOutput(); | 79 | m_console.UnlockOutput(); |
114 | } | 80 | } |
115 | } | 81 | } |
116 | |||
117 | private void WriteColorText(ConsoleColor color, string sender) | ||
118 | { | ||
119 | try | ||
120 | { | ||
121 | lock (this) | ||
122 | { | ||
123 | try | ||
124 | { | ||
125 | System.Console.ForegroundColor = color; | ||
126 | System.Console.Write(sender); | ||
127 | System.Console.ResetColor(); | ||
128 | } | ||
129 | catch (ArgumentNullException) | ||
130 | { | ||
131 | // Some older systems dont support coloured text. | ||
132 | System.Console.WriteLine(sender); | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | catch (ObjectDisposedException) | ||
137 | { | ||
138 | } | ||
139 | } | ||
140 | |||
141 | private static ConsoleColor DeriveColor(string input) | ||
142 | { | ||
143 | // it is important to do Abs, hash values can be negative | ||
144 | return Colors[(Math.Abs(input.ToUpper().GetHashCode()) % Colors.Length)]; | ||
145 | } | ||
146 | } | 82 | } |
147 | } | 83 | } |