factor out the common DeriveColor function just for good house keeping

afrisby
Sean Dague 2007-08-01 20:23:08 +00:00
parent 5c0f1ff293
commit 2507f38d07
1 changed files with 18 additions and 25 deletions

View File

@ -95,6 +95,19 @@ namespace OpenSim.Framework.Console
return; return;
} }
/// <summary>
/// derive an ansi color from a string, ignoring the darker colors.
/// This is used to help automatically bin component tags with colors
/// in various print functions.
/// </summary>
/// <param name="input">arbitrary string for input</param>
/// <returns>an ansii color</returns>
private ConsoleColor DeriveColor(string input)
{
int colIdx = (input.ToUpper().GetHashCode() % 6) + 9;
return (ConsoleColor)colIdx;
}
/// <summary> /// <summary>
/// Sends a warning to the current log output /// Sends a warning to the current log output
/// </summary> /// </summary>
@ -114,11 +127,7 @@ namespace OpenSim.Framework.Console
/// <param name="args">WriteLine-style message arguments</param> /// <param name="args">WriteLine-style message arguments</param>
public void Warn(string sender, string format, params object[] args) public void Warn(string sender, string format, params object[] args)
{ {
sender = sender.ToUpper(); WritePrefixLine(DeriveColor(sender), sender);
int colIdx = (sender.GetHashCode() % 6) + 9;
ConsoleColor col = (ConsoleColor)colIdx;
WritePrefixLine(col, sender);
WriteNewLine(ConsoleColor.Yellow, format, args); WriteNewLine(ConsoleColor.Yellow, format, args);
return; return;
} }
@ -142,11 +151,7 @@ namespace OpenSim.Framework.Console
/// <param name="args">WriteLine-style message arguments</param> /// <param name="args">WriteLine-style message arguments</param>
public void Notice(string sender, string format, params object[] args) public void Notice(string sender, string format, params object[] args)
{ {
sender = sender.ToUpper(); WritePrefixLine(DeriveColor(sender), sender);
int colIdx = (sender.GetHashCode() % 6) + 9;
ConsoleColor col = (ConsoleColor)colIdx;
WritePrefixLine(col, sender);
WriteNewLine(ConsoleColor.White, format, args); WriteNewLine(ConsoleColor.White, format, args);
return; return;
} }
@ -170,11 +175,7 @@ namespace OpenSim.Framework.Console
/// <param name="args">WriteLine-style message arguments</param> /// <param name="args">WriteLine-style message arguments</param>
public void Error(string sender, string format, params object[] args) public void Error(string sender, string format, params object[] args)
{ {
sender = sender.ToUpper(); WritePrefixLine(DeriveColor(sender), sender);
int colIdx = (sender.GetHashCode() % 6) + 9;
ConsoleColor col = (ConsoleColor)colIdx;
WritePrefixLine(col, sender);
WriteNewLine(ConsoleColor.Red, format, args); WriteNewLine(ConsoleColor.Red, format, args);
return; return;
} }
@ -198,11 +199,7 @@ namespace OpenSim.Framework.Console
/// <param name="args">WriteLine-style message arguments</param> /// <param name="args">WriteLine-style message arguments</param>
public void Verbose(string sender, string format, params object[] args) public void Verbose(string sender, string format, params object[] args)
{ {
sender = sender.ToUpper(); WritePrefixLine(DeriveColor(sender), sender);
int colIdx = (sender.GetHashCode() % 6) + 9;
ConsoleColor col = (ConsoleColor)colIdx;
WritePrefixLine(col, sender);
WriteNewLine(ConsoleColor.Gray, format, args); WriteNewLine(ConsoleColor.Gray, format, args);
return; return;
} }
@ -226,11 +223,7 @@ namespace OpenSim.Framework.Console
/// <param name="args">WriteLine-style message arguments</param> /// <param name="args">WriteLine-style message arguments</param>
public void Status(string sender, string format, params object[] args) public void Status(string sender, string format, params object[] args)
{ {
sender = sender.ToUpper(); WritePrefixLine(DeriveColor(sender), sender);
int colIdx = (sender.GetHashCode() % 6) + 9;
ConsoleColor col = (ConsoleColor)colIdx;
WritePrefixLine(col, sender);
WriteNewLine(ConsoleColor.Blue, format, args); WriteNewLine(ConsoleColor.Blue, format, args);
return; return;
} }