// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
using System.Diagnostics;
namespace FlaxEngine
{
///
/// Class containing methods to ease debugging while developing a game.
///
public static class Debug
{
internal static Logger _logger = new Logger(new DebugLogHandler());
///
/// Get default debug logger.
///
[HideInEditor]
public static ILogger Logger => _logger;
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
[Conditional("FLAX_ASSERTIONS")]
[Obsolete("Please use verbose logging for all exceptions")]
public static void Assert(bool condition)
{
if (!condition)
Logger.Log(LogType.Error, "Assertion failed");
}
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
/// Object to which the message applies.
[Conditional("FLAX_ASSERTIONS")]
public static void Assert(bool condition, Object context)
{
if (!condition)
Logger.Log(LogType.Error, (object)"Assertion failed", context);
}
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
/// String or object to be converted to string representation for display.
[Conditional("FLAX_ASSERTIONS")]
public static void Assert(bool condition, object message)
{
if (!condition)
Logger.Log(LogType.Error, message);
}
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
/// String to be converted to string representation for display.
[Conditional("FLAX_ASSERTIONS")]
public static void Assert(bool condition, string message)
{
if (!condition)
Logger.Log(LogType.Error, message);
}
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
/// Object to which the message applies.
/// String or object to be converted to string representation for display.
[Conditional("FLAX_ASSERTIONS")]
public static void Assert(bool condition, object message, Object context)
{
if (!condition)
Logger.Log(LogType.Error, message, context);
}
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
/// Object to which the message applies.
/// String to be converted to string representation for display.
[Conditional("FLAX_ASSERTIONS")]
public static void Assert(bool condition, string message, Object context)
{
if (!condition)
Logger.Log(LogType.Error, (object)message, context);
}
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
/// A composite format string.
/// Format arguments.
[Conditional("FLAX_ASSERTIONS")]
public static void AssertFormat(bool condition, string format, params object[] args)
{
if (!condition)
Logger.LogFormat(LogType.Error, format, args);
}
///
/// Assert a condition and logs a formatted error message to the Flax console on failure.
///
/// Condition you expect to be true.
/// A composite format string.
/// Format arguments.
/// Object to which the message applies.
[Conditional("FLAX_ASSERTIONS")]
public static void AssertFormat(bool condition, Object context, string format, params object[] args)
{
if (!condition)
Logger.Log(LogType.Error, context, string.Format(format, args));
}
///
/// Logs the raw message to the log.
///
/// Type of the log message. Not: fatal will stop the engine. Error may show a message popup.
/// The message contents.
public static void Write(LogType logType, string message)
{
Logger.LogHandler.LogWrite(logType, message);
}
///
/// Logs message to the Flax Console.
///
/// String or object to be converted to string representation for display.
public static void Log(object message)
{
Logger.Log(LogType.Info, message);
}
///
/// Logs message to the Flax Console.
///
/// String or object to be converted to string representation for display.
/// Object to which the message applies.
public static void Log(object message, Object context)
{
Logger.Log(LogType.Info, message, context);
}
///
/// A variant of Debug.Info that logs an assertion message to the console.
///
/// String or object to be converted to string representation for display.
[Conditional("FLAX_ASSERTIONS")]
public static void LogAssertion(object message)
{
Logger.Log(LogType.Error, message);
}
///
/// A variant of Debug.Info that logs an assertion message to the console.
///
/// String or object to be converted to string representation for display.
/// Object to which the message applies.
[Conditional("FLAX_ASSERTIONS")]
public static void LogAssertion(object message, Object context)
{
Logger.Log(LogType.Error, message, context);
}
///
/// Logs a formatted assertion message to the Flax console.
///
/// A composite format string.
/// Format arguments.
[Conditional("FLAX_ASSERTIONS")]
public static void LogAssertionFormat(string format, params object[] args)
{
Logger.LogFormat(LogType.Error, format, args);
}
///
/// Logs a formatted assertion message to the Flax console.
///
/// A composite format string.
/// Format arguments.
/// Object to which the message applies.
[Conditional("FLAX_ASSERTIONS")]
public static void LogAssertionFormat(Object context, string format, params object[] args)
{
Logger.Log(LogType.Error, context, string.Format(format, args));
}
///
/// A variant of Debug.Info that logs an error message to the console.
///
/// String or object to be converted to string representation for display.
public static void LogError(object message)
{
Logger.Log(LogType.Error, message);
}
///
/// A variant of Debug.Info that logs an error message to the console.
///
/// String or object to be converted to string representation for display.
/// Object to which the message applies.
public static void LogError(object message, Object context)
{
Logger.Log(LogType.Error, message, context);
}
///
/// Logs a formatted error message to the Flax console.
///
/// A composite format string.
/// Format arguments.
public static void LogErrorFormat(string format, params object[] args)
{
Logger.LogFormat(LogType.Error, format, args);
}
///
/// Logs a formatted error message to the Flax console.
///
/// A composite format string.
/// Format arguments.
/// Object to which the message applies.
public static void LogErrorFormat(Object context, string format, params object[] args)
{
Logger.Log(LogType.Error, context, string.Format(format, args));
}
///
/// A variant of Debug.Info that logs an error message to the console.
///
/// Runtime Exception.
public static void LogException(Exception exception)
{
Logger.LogException(exception, null);
if (exception.InnerException != null)
{
LogWarning("Inner exception:");
LogException(exception.InnerException);
}
}
///
/// A variant of Debug.Info that logs an error message to the console.
///
/// Object to which the message applies.
/// Runtime Exception.
public static void LogException(Exception exception, Object context)
{
Logger.LogException(exception, context);
if (exception.InnerException != null)
{
LogWarning("Inner exception:");
LogException(exception.InnerException, context);
}
}
///
/// Logs a formatted message to the Flax Console.
///
/// A composite format string.
/// Format arguments.
public static void LogFormat(string format, params object[] args)
{
Logger.LogFormat(LogType.Info, format, args);
}
///
/// Logs a formatted message to the Flax Console.
///
/// A composite format string.
/// Format arguments.
/// Object to which the message applies.
public static void LogFormat(Object context, string format, params object[] args)
{
Logger.Log(LogType.Info, context, string.Format(format, args));
}
///
/// A variant of Debug.Info that logs a warning message to the console.
///
/// String or object to be converted to string representation for display.
public static void LogWarning(object message)
{
Logger.Log(LogType.Warning, message);
}
///
/// A variant of Debug.Info that logs a warning message to the console.
///
/// String or object to be converted to string representation for display.
/// Object to which the message applies.
public static void LogWarning(object message, Object context)
{
Logger.Log(LogType.Warning, message, context);
}
///
/// Logs a formatted warning message to the Flax Console.
///
/// A composite format string.
/// Format arguments.
public static void LogWarningFormat(string format, params object[] args)
{
Logger.Log(LogType.Warning, format, args);
}
///
/// Logs a formatted warning message to the Flax Console.
///
/// A composite format string.
/// Format arguments.
/// Object to which the message applies.
public static void LogWarningFormat(Object context, string format, params object[] args)
{
Logger.Log(LogType.Warning, context, string.Format(format, args));
}
}
}