* New log functions which include the module name as an argument.

afrisby
Adam Frisby 2007-07-20 01:21:39 +00:00
parent 6c96de1f57
commit f5b24b6679
1 changed files with 134 additions and 0 deletions

View File

@ -90,36 +90,142 @@ namespace OpenSim.Framework.Console
return; return;
} }
/// <summary>
/// Sends a warning to the current log output
/// </summary>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
public void Warn(string format, params object[] args) public void Warn(string format, params object[] args)
{ {
WriteNewLine(ConsoleColor.Yellow, format, args); WriteNewLine(ConsoleColor.Yellow, format, args);
return; return;
} }
/// <summary>
/// Sends a warning to the current log output
/// </summary>
/// <param name="sender">The module that sent this message</param>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
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;
}
/// <summary>
/// Sends a notice to the current log output
/// </summary>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
public void Notice(string format, params object[] args) public void Notice(string format, params object[] args)
{ {
WriteNewLine(ConsoleColor.White, format, args); WriteNewLine(ConsoleColor.White, format, args);
return; return;
} }
/// <summary>
/// Sends a notice to the current log output
/// </summary>
/// <param name="sender">The module that sent this message</param>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
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;
}
/// <summary>
/// Sends an error to the current log output
/// </summary>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
public void Error(string format, params object[] args) public void Error(string format, params object[] args)
{ {
WriteNewLine(ConsoleColor.Red, format, args); WriteNewLine(ConsoleColor.Red, format, args);
return; return;
} }
/// <summary>
/// Sends an error to the current log output
/// </summary>
/// <param name="sender">The module that sent this message</param>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
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;
}
/// <summary>
/// Sends a informational message to the current log output
/// </summary>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
public void Verbose(string format, params object[] args) public void Verbose(string format, params object[] args)
{ {
WriteNewLine(ConsoleColor.Gray, format, args); WriteNewLine(ConsoleColor.Gray, format, args);
return; return;
} }
/// <summary>
/// Sends an informational message to the current log output
/// </summary>
/// <param name="sender">The module that sent this message</param>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
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;
}
/// <summary>
/// Sends a status message to the current log output
/// </summary>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
public void Status(string format, params object[] args) public void Status(string format, params object[] args)
{ {
WriteNewLine(ConsoleColor.Blue, format, args); WriteNewLine(ConsoleColor.Blue, format, args);
return; return;
} }
/// <summary>
/// Sends a status message to the current log output
/// </summary>
/// <param name="sender">The module that sent this message</param>
/// <param name="format">The message to send</param>
/// <param name="args">WriteLine-style message arguments</param>
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) private void WriteNewLine(ConsoleColor color, string format, params object[] args)
{ {
Log.WriteLine(format, args); Log.WriteLine(format, args);
@ -141,6 +247,34 @@ namespace OpenSim.Framework.Console
return; 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() public string ReadLine()
{ {
string TempStr = System.Console.ReadLine(); string TempStr = System.Console.ReadLine();