From f5b24b66799c4f31a792b70e2eb246f0e58b5254 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 20 Jul 2007 01:21:39 +0000 Subject: * New log functions which include the module name as an argument. --- OpenSim/Framework/Console/LogBase.cs | 134 +++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/OpenSim/Framework/Console/LogBase.cs b/OpenSim/Framework/Console/LogBase.cs index 1eb6ff0..db76861 100644 --- a/OpenSim/Framework/Console/LogBase.cs +++ b/OpenSim/Framework/Console/LogBase.cs @@ -90,36 +90,142 @@ namespace OpenSim.Framework.Console return; } + /// + /// Sends a warning to the current log output + /// + /// The message to send + /// WriteLine-style message arguments public void Warn(string format, params object[] args) { WriteNewLine(ConsoleColor.Yellow, format, args); return; } + /// + /// Sends a warning to the current log output + /// + /// The module that sent this message + /// The message to send + /// WriteLine-style message arguments + public void Warn(string sender, string format, params object[] args) + { + int colIdx = (sender.GetHashCode() % 6) + 9; + ConsoleColor col = (ConsoleColor)colIdx; + + WritePrefixLine(col, sender); + WriteNewLine(ConsoleColor.Yellow, format, args); + return; + } + + /// + /// Sends a notice to the current log output + /// + /// The message to send + /// WriteLine-style message arguments public void Notice(string format, params object[] args) { WriteNewLine(ConsoleColor.White, format, args); return; } + /// + /// Sends a notice to the current log output + /// + /// The module that sent this message + /// The message to send + /// WriteLine-style message arguments + public void Notice(string sender, string format, params object[] args) + { + int colIdx = (sender.GetHashCode() % 6) + 9; + ConsoleColor col = (ConsoleColor)colIdx; + + WritePrefixLine(col, sender); + WriteNewLine(ConsoleColor.White, format, args); + return; + } + + /// + /// Sends an error to the current log output + /// + /// The message to send + /// WriteLine-style message arguments public void Error(string format, params object[] args) { WriteNewLine(ConsoleColor.Red, format, args); return; } + /// + /// Sends an error to the current log output + /// + /// The module that sent this message + /// The message to send + /// WriteLine-style message arguments + public void Error(string sender, string format, params object[] args) + { + int colIdx = (sender.GetHashCode() % 6) + 9; + ConsoleColor col = (ConsoleColor)colIdx; + + WritePrefixLine(col, sender); + WriteNewLine(ConsoleColor.Red, format, args); + return; + } + + /// + /// Sends a informational message to the current log output + /// + /// The message to send + /// WriteLine-style message arguments public void Verbose(string format, params object[] args) { WriteNewLine(ConsoleColor.Gray, format, args); return; } + /// + /// Sends an informational message to the current log output + /// + /// The module that sent this message + /// The message to send + /// WriteLine-style message arguments + public void Verbose(string sender, string format, params object[] args) + { + int colIdx = (sender.GetHashCode() % 6) + 9; + ConsoleColor col = (ConsoleColor)colIdx; + + WritePrefixLine(col, sender); + WriteNewLine(ConsoleColor.Gray, format, args); + return; + } + + /// + /// Sends a status message to the current log output + /// + /// The message to send + /// WriteLine-style message arguments public void Status(string format, params object[] args) { WriteNewLine(ConsoleColor.Blue, format, args); return; } + /// + /// Sends a status message to the current log output + /// + /// The module that sent this message + /// The message to send + /// WriteLine-style message arguments + public void Status(string sender, string format, params object[] args) + { + int colIdx = (sender.GetHashCode() % 6) + 9; + ConsoleColor col = (ConsoleColor)colIdx; + + WritePrefixLine(col, sender); + WriteNewLine(ConsoleColor.Blue, format, args); + return; + } + + private void WriteNewLine(ConsoleColor color, string format, params object[] args) { Log.WriteLine(format, args); @@ -141,6 +247,34 @@ namespace OpenSim.Framework.Console return; } + private void WritePrefixLine(ConsoleColor color, string sender) + { + Log.WriteLine("[" + sender + "] "); + Log.Flush(); + + System.Console.Write("["); + + if (!m_silent) + { + try + { + System.Console.ForegroundColor = color; + System.Console.Write(sender); + System.Console.ResetColor(); + } + catch (ArgumentNullException) + { + // Some older systems dont support coloured text. + System.Console.WriteLine(sender); + } + } + + System.Console.Write("] "); + + return; + } + + public string ReadLine() { string TempStr = System.Console.ReadLine(); -- cgit v1.1