using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Jovian.Logger {
///
/// Default logger for Custom Logger in case you don't want to create a new instance of CustomLogger
/// Recommended is to create a new instance of CustomLogger
///
public static class GlobalLogger {
///
/// Logs messages that are meant to only be seen in the editor
///
/// Log message
/// Optional Log Category
/// Implicit, do not provide
[Conditional("UNITY_EDITOR")] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogSpam(string msg, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogSpam($"{GetCaller()?.Name}.{callerMethod}", msg, logCat);
}
///
/// Logs messages that are meant to only be seen in the editor with a context object
///
/// Log message
/// Object to select in scene/project
/// Optional Log Category
/// Implicit, do not provide
[Conditional("UNITY_EDITOR")] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogSpam(string msg, UnityEngine.Object context, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogSpam($"{GetCaller()?.Name}.{callerMethod}", msg, logCat, context);
}
///
/// Logs standard Info/Debug messages
///
///
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogInfo(string msg, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogInfo($"{GetCaller()?.Name}.{callerMethod}", msg, logCat);
}
///
/// Logs standard Info/Debug messagesc with a context object
///
///
/// Object to select in scene/project
///
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogInfo(string msg, UnityEngine.Object context, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogInfo($"{GetCaller()?.Name}.{callerMethod}", msg, logCat, context);
}
///
/// Logs standard Warning messages
///
///
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogWarning(string msg, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogWarning($"{GetCaller()?.Name}.{callerMethod}", msg, logCat);
}
///
/// Logs standard Warning messages with a context object
///
///
/// Object to select in scene/project
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogWarning(string msg, UnityEngine.Object context, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogWarning($"{GetCaller()?.Name}.{callerMethod}", msg, logCat, context);
}
///
/// Logs standard Error messages
///
///
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogError(string msg, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogError($"{GetCaller()?.Name}.{callerMethod}", msg, logCat);
}
///
/// Logs standard Error messages with a context object
///
///
/// Optional Log Category
/// Object to select in scene/project
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogError(string msg, UnityEngine.Object context, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogError($"{GetCaller()?.Name}.{callerMethod}", msg, logCat, context);
}
///
/// Logs standard Assert messages
///
///
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogAssert(string msg, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogAssert($"{GetCaller()?.Name}.{callerMethod}", msg, logCat);
}
///
/// Logs standard Assert messages with a context object
///
///
/// Object to select in scene/project
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogAssert(string msg, UnityEngine.Object context, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogAssert($"{GetCaller()?.Name}.{callerMethod}", msg, logCat, context);
}
///
/// Logs string Exception messages
///
///
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogException(string msg, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogException($"{GetCaller()?.Name}.{callerMethod}", msg, logCat);
}
///
/// Logs string Exception messages with a context object
///
///
/// Object to select in scene/project
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogException(string msg, UnityEngine.Object context, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogException($"{GetCaller()?.Name}.{callerMethod}", msg, logCat, context);
}
///
/// Logs standard Exception messages
///
///
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogException(Exception e, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogException($"{GetCaller()?.Name}.{callerMethod}", e.Message, logCat);
}
///
/// Logs standard Exception messages with a context object
///
///
/// Object to select in scene/project
/// Optional Log Category
/// Implicit, do not provide
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogException(Exception e, UnityEngine.Object context, LogCategory logCat, [CallerMemberName] string callerMethod = "") {
InternalLogger.LogException($"{GetCaller()?.Name}.{callerMethod}", e.Message, logCat, context);
}
private static Type GetCaller() {
var stackTrace = new StackTrace();
var stackFrame = stackTrace.GetFrame(2);
var caller = stackFrame?.GetMethod()?.DeclaringType;
return caller;
}
}
}