diff options
author | Sean Dague | 2008-02-06 20:32:37 +0000 |
---|---|---|
committer | Sean Dague | 2008-02-06 20:32:37 +0000 |
commit | b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc (patch) | |
tree | 32758b8055f13daead9e4aa57bf84f657d25d887 | |
parent | Shortened console log messages. (diff) | |
download | opensim-SC-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.zip opensim-SC-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.tar.gz opensim-SC-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.tar.bz2 opensim-SC-b3e85daf02f3ea6e4b4fc33defa1a4e2a7ae54dc.tar.xz |
pass 1 on getting colors back to the console
-rw-r--r-- | OpenSim/Framework/Console/OpenSimAppender.cs | 69 | ||||
-rw-r--r-- | bin/OpenSim.exe.config | 4 |
2 files changed, 71 insertions, 2 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 @@ | |||
1 | using System; | ||
2 | using System.Text; | ||
3 | using System.Text.RegularExpressions; | ||
4 | using System.Globalization; | ||
5 | |||
6 | using log4net.Core; | ||
7 | using log4net.Layout; | ||
8 | using log4net.Appender; | ||
9 | using log4net.Util; | ||
10 | |||
11 | namespace 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 | ||
diff --git a/bin/OpenSim.exe.config b/bin/OpenSim.exe.config index e4f8c65..0c6b1df 100644 --- a/bin/OpenSim.exe.config +++ b/bin/OpenSim.exe.config | |||
@@ -6,9 +6,9 @@ | |||
6 | <appSettings> | 6 | <appSettings> |
7 | </appSettings> | 7 | </appSettings> |
8 | <log4net> | 8 | <log4net> |
9 | <appender name="Console" type="log4net.Appender.ConsoleAppender"> | 9 | <appender name="Console" type="OpenSim.Framework.Console.OpenSimAppender, OpenSim.Framework.Console"> |
10 | <layout type="log4net.Layout.PatternLayout"> | 10 | <layout type="log4net.Layout.PatternLayout"> |
11 | <conversionPattern value="%message%newline" /> | 11 | <conversionPattern value="%-5level - %message%newline" /> |
12 | </layout> | 12 | </layout> |
13 | </appender> | 13 | </appender> |
14 | <appender name="LogFileAppender" type="log4net.Appender.FileAppender"> | 14 | <appender name="LogFileAppender" type="log4net.Appender.FileAppender"> |