using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TechbloxModdingAPI.Utility { /// /// Utility class to access Techblox's built-in logging capabilities. /// The log is saved to %APPDATA%\..\LocalLow\FreeJam\Techblox\Player.Log /// public static class Logging { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Log(string msg) { Svelto.Console.Log(msg); } /// /// Write a regular message to Techblox's log /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Log(object obj) { Svelto.Console.Log(obj.ToString()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogDebug(string msg) { Svelto.Console.LogDebug(msg); } /// /// Write a debug message to Techblox's log /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogDebug(object obj) { Svelto.Console.LogDebug(obj.ToString()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogDebug(string msg, T extraDebug) { Svelto.Console.LogDebug(msg, extraDebug); } /// /// Write a debug message and object to Techblox's log /// The reason this method exists in Svelto.Console is beyond my understanding /// /// The type of the extra debug object /// The object to log /// The extra object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogDebug(object obj, T extraDebug) { Svelto.Console.LogDebug(obj.ToString(), extraDebug); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogError(string msg, Dictionary extraData = null) { Svelto.Console.LogError(msg, extraData); } /// /// Write an error message to Techblox's log /// /// The object to log /// The extra data to pass to the ILogger [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogError(object obj, Dictionary extraData = null) { Svelto.Console.LogError(obj.ToString(), extraData); } /// /// Write an exception to Techblox's log and to the screen and exit game /// /// The exception to log /// The extra data to pass to the ILogger. /// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogException(Exception e, string msg = null, Dictionary extraData = null) { Svelto.Console.LogException(e, msg, extraData); } /// /// Write an exception message to Techblox's log and to the screen and exit game /// /// The object to log /// The exception to log /// The extra data to pass to the ILogger. /// This is implemented similar to LogException(Exception e, Dictionary extraData)'s extraData [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogException(Exception e, object obj, Dictionary extraData = null) { Svelto.Console.LogException(e, obj.ToString(), extraData); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogWarning(string msg) { Svelto.Console.LogWarning(msg); } /// /// Write a warning message to Techblox's log /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LogWarning(object obj) { Svelto.Console.LogWarning(obj.ToString()); } // descriptive logging /// /// Write a descriptive message to Techblox's log only when the API is a Debug build /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MetaDebugLog(object obj) { #if DEBUG MetaLog($"[MetaDebug]{obj.ToString()}"); #endif } /// /// Write a descriptive message to Techblox's log including the current time and the calling method's name /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MetaLog(object obj) { var method = (new StackTrace()).GetFrame(1).GetMethod(); Log($"[{DateTime.Now.ToString()}][{method.DeclaringType.FullName}.{method.Name}]{obj.ToString()}"); } // CLI logging /// /// Write a message to Techblox's command line /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CommandLog(object obj) { CommandLog(obj.ToString()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CommandLog(string msg) { uREPL.Log.Output(msg); } /// /// Write an error message to Techblox's command line /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CommandLogError(object obj) { CommandLogError(obj.ToString()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CommandLogError(string msg) { uREPL.Log.Error(msg); } /// /// Write a warning message to Techblox's command line /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CommandLogWarning(object obj) { CommandLogWarning(obj.ToString()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CommandLogWarning(string msg) { uREPL.Log.Warn(msg); } } }