using System;
namespace IgniteEngine
{
///
/// Class containing methods to ease debugging while developing a server.
///
public static class Debug
{
///
/// Logs a message to the console window.
///
/// The message to log.
public static void Log(object message)
{
Print(DebugLevel.DL_LOG, message, null);
}
///
/// Logs a message to the console window.
///
/// The message to log.
/// The that the message references.
public static void Log(object message, Object context)
{
Print(DebugLevel.DL_LOG, message, context);
}
///
/// Logs an assert message to the console window.
///
/// The message to log.
public static void LogAssert(object message)
{
Print(DebugLevel.DL_ASSERT, message, null);
}
///
/// Logs an assert message to the console window.
///
/// The message to log.
/// The that the message references.
public static void LogAssert(object message, Object context)
{
Print(DebugLevel.DL_ASSERT, message, context);
}
///
/// Logs an error message to the console window.
///
/// The message to log.
public static void LogError(object message)
{
Print(DebugLevel.DL_ERROR, message, null);
}
///
/// Logs an error message to the console window.
///
/// The message to log.
/// The that the message references.
public static void LogError(object message, Object context)
{
Print(DebugLevel.DL_ERROR, message, context);
}
///
/// Logs an exception message to the console window.
///
/// The message to log.
public static void LogException(object message)
{
Print(DebugLevel.DL_EXCEPTION, message, null);
}
///
/// Logs an exception message to the console window.
///
/// The message to log.
/// The that the message references.
public static void LogException(object message, Object context)
{
Print(DebugLevel.DL_EXCEPTION, message, context);
}
///
/// Logs a warning message to the console window.
///
/// The message to log.
public static void LogWarning(object message)
{
Print(DebugLevel.DL_WARNING, message, null);
}
///
/// Logs a warning message to the console window.
///
/// The message to log.
/// The that the message references.
public static void LogWarning(object message, Object context)
{
Print(DebugLevel.DL_WARNING, message, context);
}
///
/// Gets the appropriate color for the log message.
///
/// The type of the log message.
/// The color to set the console window to.
private static ConsoleColor GetColor(DebugLevel type)
{
switch (type)
{
case DebugLevel.DL_LOG:
return ConsoleColor.Gray;
case DebugLevel.DL_ERROR:
case DebugLevel.DL_EXCEPTION:
return ConsoleColor.Magenta;
case DebugLevel.DL_ASSERT:
case DebugLevel.DL_WARNING:
return ConsoleColor.Yellow;
default:
return ConsoleColor.Gray;
}
}
///
/// Prints a message to the console window.
///
/// The type of the message.
/// The message to print.
/// The object that the message references.
private static void Print(DebugLevel level, object message, Object context)
{
Console.ForegroundColor = GetColor(level);
Console.WriteLine($"{message}{(context ? $" (Context: {context})" : string.Empty)}");
Console.ResetColor();
}
}
}