aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-20 14:40:50 +0000
committerMelanie Thielker2009-05-20 14:40:50 +0000
commit3ae9bb6d83540ef5acf3cbe4969d0f9c01164d21 (patch)
tree2f8fe335030dd70795fba2a6334e150c1fab19a4 /OpenSim
parentRemove the pre-log4net, discrete output methods from the consoles (diff)
downloadopensim-SC-3ae9bb6d83540ef5acf3cbe4969d0f9c01164d21.zip
opensim-SC-3ae9bb6d83540ef5acf3cbe4969d0f9c01164d21.tar.gz
opensim-SC-3ae9bb6d83540ef5acf3cbe4969d0f9c01164d21.tar.bz2
opensim-SC-3ae9bb6d83540ef5acf3cbe4969d0f9c01164d21.tar.xz
Move the color console logic from the appender into the local console, since
that is the only one that can use it. Change appender output to always go through the console output functions.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/ConsoleBase.cs7
-rw-r--r--OpenSim/Framework/Console/LocalConsole.cs86
-rw-r--r--OpenSim/Framework/Console/OpenSimAppender.cs82
-rw-r--r--OpenSim/Framework/Console/RemoteConsole.cs3
4 files changed, 101 insertions, 77 deletions
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 0747ae5..6e00888 100644
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -66,9 +66,14 @@ namespace OpenSim.Framework.Console
66 { 66 {
67 } 67 }
68 68
69 public virtual void Output(string text, string level)
70 {
71 Output(text);
72 }
73
69 public virtual void Output(string text) 74 public virtual void Output(string text)
70 { 75 {
71 System.Console.WriteLine(text); 76 System.Console.Write(text);
72 } 77 }
73 78
74 public string CmdPrompt(string p) 79 public string CmdPrompt(string p)
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs
index ca57bd6..4d768b9 100644
--- a/OpenSim/Framework/Console/LocalConsole.cs
+++ b/OpenSim/Framework/Console/LocalConsole.cs
@@ -30,6 +30,7 @@ using System.Collections.Generic;
30using System.Diagnostics; 30using System.Diagnostics;
31using System.Reflection; 31using System.Reflection;
32using System.Text; 32using System.Text;
33using System.Text.RegularExpressions;
33using System.Threading; 34using System.Threading;
34using log4net; 35using log4net;
35 36
@@ -50,6 +51,28 @@ namespace OpenSim.Framework.Console
50 private bool echo = true; 51 private bool echo = true;
51 private List<string> history = new List<string>(); 52 private List<string> history = new List<string>();
52 53
54 private static readonly ConsoleColor[] Colors = {
55 // the dark colors don't seem to be visible on some black background terminals like putty :(
56 //ConsoleColor.DarkBlue,
57 //ConsoleColor.DarkGreen,
58 //ConsoleColor.DarkCyan,
59 //ConsoleColor.DarkMagenta,
60 //ConsoleColor.DarkYellow,
61 ConsoleColor.Gray,
62 //ConsoleColor.DarkGray,
63 ConsoleColor.Blue,
64 ConsoleColor.Green,
65 ConsoleColor.Cyan,
66 ConsoleColor.Magenta,
67 ConsoleColor.Yellow
68 };
69
70 private static ConsoleColor DeriveColor(string input)
71 {
72 // it is important to do Abs, hash values can be negative
73 return Colors[(Math.Abs(input.ToUpper().GetHashCode()) % Colors.Length)];
74 }
75
53 public LocalConsole(string defaultPrompt) : base(defaultPrompt) 76 public LocalConsole(string defaultPrompt) : base(defaultPrompt)
54 { 77 {
55 } 78 }
@@ -158,13 +181,72 @@ namespace OpenSim.Framework.Console
158 Monitor.Exit(cmdline); 181 Monitor.Exit(cmdline);
159 } 182 }
160 183
184 private void WriteColorText(ConsoleColor color, string sender)
185 {
186 try
187 {
188 lock (this)
189 {
190 try
191 {
192 System.Console.ForegroundColor = color;
193 System.Console.Write(sender);
194 System.Console.ResetColor();
195 }
196 catch (ArgumentNullException)
197 {
198 // Some older systems dont support coloured text.
199 System.Console.WriteLine(sender);
200 }
201 }
202 }
203 catch (ObjectDisposedException)
204 {
205 }
206 }
207
208 private void WriteLocalText(string text, string level)
209 {
210 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)";
211
212 Regex RE = new Regex(regex, RegexOptions.Multiline);
213 MatchCollection matches = RE.Matches(text);
214
215 string outText = text;
216 ConsoleColor color = ConsoleColor.White;
217
218 if (matches.Count == 1)
219 {
220 outText = matches[0].Groups["End"].Value;
221 System.Console.Write(matches[0].Groups["Front"].Value);
222
223 System.Console.Write("[");
224 WriteColorText(DeriveColor(matches[0].Groups["Category"].Value),
225 matches[0].Groups["Category"].Value);
226 System.Console.Write("]:");
227 }
228
229 if (level == "error")
230 color = ConsoleColor.Red;
231 else if (level == "warn")
232 color = ConsoleColor.Yellow;
233
234 WriteColorText(color, outText);
235 System.Console.WriteLine();
236 }
237
161 public override void Output(string text) 238 public override void Output(string text)
162 { 239 {
240 Output(text, "normal");
241 }
242
243 public override void Output(string text, string level)
244 {
163 lock (cmdline) 245 lock (cmdline)
164 { 246 {
165 if (y == -1) 247 if (y == -1)
166 { 248 {
167 System.Console.WriteLine(text); 249 WriteLocalText(text, level);
168 250
169 return; 251 return;
170 } 252 }
@@ -180,7 +262,7 @@ namespace OpenSim.Framework.Console
180 y = SetCursorTop(y); 262 y = SetCursorTop(y);
181 System.Console.CursorLeft = 0; 263 System.Console.CursorLeft = 0;
182 264
183 System.Console.WriteLine(text); 265 WriteLocalText(text, level);
184 266
185 y = System.Console.CursorTop; 267 y = System.Console.CursorTop;
186 268
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
28using System; 28using System;
29using System.Text.RegularExpressions;
30using log4net.Appender; 29using log4net.Appender;
31using log4net.Core; 30using 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}
diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs
index ea46afd..fdbf1f4 100644
--- a/OpenSim/Framework/Console/RemoteConsole.cs
+++ b/OpenSim/Framework/Console/RemoteConsole.cs
@@ -60,8 +60,9 @@ namespace OpenSim.Framework.Console
60 m_Server = server; 60 m_Server = server;
61 } 61 }
62 62
63 public override void Output(string text) 63 public override void Output(string text, string level)
64 { 64 {
65 System.Console.Write(text);
65 } 66 }
66 67
67 public override string ReadLine(string p, bool isCommand, bool e) 68 public override string ReadLine(string p, bool isCommand, bool e)