|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace GamecraftModdingAPI.Utility
- {
- /// <summary>
- /// Utility class to access Gamecraft's built-in logging capabilities.
- /// The log is saved to %APPDATA%\..\LocalLow\FreeJam\Gamecraft\Player.Log
- /// </summary>
- public static class Logging
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Log(string msg)
- {
- Svelto.Console.Log(msg);
- }
-
- /// <summary>
- /// Write a regular message to Gamecraft's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- [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);
- }
-
- /// <summary>
- /// Write a debug message to Gamecraft's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogDebug(object obj)
- {
- Svelto.Console.LogDebug(obj.ToString());
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogDebug<T>(string msg, T extraDebug)
- {
- Svelto.Console.LogDebug<T>(msg, extraDebug);
- }
-
- /// <summary>
- /// Write a debug message and object to Gamecraft's log
- /// The reason this method exists in Svelto.Console is beyond my understanding
- /// </summary>
- /// <typeparam name="T">The type of the extra debug object</typeparam>
- /// <param name="obj">The object to log</param>
- /// <param name="extraDebug">The extra object to log</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogDebug<T>(object obj, T extraDebug)
- {
- Svelto.Console.LogDebug<T>(obj.ToString(), extraDebug);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogError(string msg, Dictionary<string, string> extraData = null)
- {
- Svelto.Console.LogError(msg, extraData);
- }
-
- /// <summary>
- /// Write an error message to Gamecraft's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- /// <param name="extraData">The extra data to pass to the ILogger</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogError(object obj, Dictionary<string, string> extraData = null)
- {
- Svelto.Console.LogError(obj.ToString(), extraData);
- }
-
- /// <summary>
- /// Write an exception to Gamecraft's log
- /// </summary>
- /// <param name="e">The exception to log</param>
- /// <param name="extraData">The extra data to pass to the ILogger.
- /// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogException(Exception e, string msg = null, Dictionary<string, string> extraData = null)
- {
- Svelto.Console.LogException(e, msg, extraData);
- }
-
- /// <summary>
- /// Write an exception message to Gamecraft's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- /// <param name="e">The exception to log</param>
- /// <param name="extraData">The extra data to pass to the ILogger.
- /// This is implemented similar to LogException(Exception e, Dictionary extraData)'s extraData</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogException(Exception e, object obj, Dictionary<string, string> extraData = null)
- {
- Svelto.Console.LogException(e, obj.ToString(), extraData);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogWarning(string msg)
- {
- Svelto.Console.LogWarning(msg);
- }
-
- /// <summary>
- /// Write a warning message to Gamecraft's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogWarning(object obj)
- {
- Svelto.Console.LogWarning(obj.ToString());
- }
-
- [Obsolete("SystemLog was removed from Svelto.Common")]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void SystemLog(string msg)
- {
- Svelto.Console.Log(msg);
- }
-
- /// <summary>
- /// Write a message to stdout (ie the terminal, like Command Prompt or PowerShell)
- /// </summary>
- /// <param name="obj">The object to log</param>
- [Obsolete("SystemLog was removed from Svelto.Common")]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void SystemLog(object obj)
- {
- Svelto.Console.Log(obj.ToString());
- }
-
- // descriptive logging
-
- /// <summary>
- /// Write a descriptive message to Gamecraft's log only when the API is a Debug build
- /// </summary>
- /// <param name="obj">The object to log</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MetaDebugLog(object obj)
- {
- #if DEBUG
- MetaLog($"[MetaDebug]{obj.ToString()}");
- #endif
- }
-
- /// <summary>
- /// Write a descriptive message to Gamecraft's log including the current time and the calling method's name
- /// </summary>
- /// <param name="obj">The object to log</param>
- [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
-
- /// <summary>
- /// Write a message to Gamecraft's command line
- /// </summary>
- /// <param name="obj">The object to log</param>
- [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);
- }
-
- /// <summary>
- /// Write an error message to Gamecraft's command line
- /// </summary>
- /// <param name="obj">The object to log</param>
- [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);
- }
-
- /// <summary>
- /// Write a warning message to Gamecraft's command line
- /// </summary>
- /// <param name="obj">The object to log</param>
- [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);
- }
-
- }
- }
|