From 4b14302bf72f16cb8c31f6bae960c15bc046b24d Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Wed, 28 Apr 2021 23:57:29 -0400 Subject: [PATCH] feat: add logger class --- XivCommon/Functions/BattleTalk.cs | 4 ++-- XivCommon/Functions/ChatBubbles.cs | 8 ++++---- XivCommon/Functions/PartyFinder.cs | 2 +- XivCommon/Functions/Talk.cs | 4 ++-- XivCommon/Logger.cs | 26 ++++++++++++++++++++++++++ XivCommon/Util.cs | 2 +- 6 files changed, 36 insertions(+), 10 deletions(-) create mode 100755 XivCommon/Logger.cs diff --git a/XivCommon/Functions/BattleTalk.cs b/XivCommon/Functions/BattleTalk.cs index 5443f04..761679d 100755 --- a/XivCommon/Functions/BattleTalk.cs +++ b/XivCommon/Functions/BattleTalk.cs @@ -66,7 +66,7 @@ namespace XivCommon.Functions { try { return this.AddBattleTalkDetourInner(uiModule, senderPtr, messagePtr, duration, style); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in BattleTalk detour"); + Logger.LogError(ex, "Exception in BattleTalk detour"); } Return: @@ -89,7 +89,7 @@ namespace XivCommon.Functions { try { this.OnBattleTalk?.Invoke(ref sender, ref message, ref options, ref handled); } catch (Exception ex) { - PluginLog.Log(ex, "Exception in BattleTalk event"); + Logger.LogError(ex, "Exception in BattleTalk event"); } if (handled) { diff --git a/XivCommon/Functions/ChatBubbles.cs b/XivCommon/Functions/ChatBubbles.cs index 4424eed..0100715 100755 --- a/XivCommon/Functions/ChatBubbles.cs +++ b/XivCommon/Functions/ChatBubbles.cs @@ -89,7 +89,7 @@ namespace XivCommon.Functions { try { this.OpenChatBubbleDetourInner(manager, actor, text, a4); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in chat bubble detour"); + Logger.LogError(ex, "Exception in chat bubble detour"); this.OpenChatBubbleHook!.Original(manager, actor, text, a4); } } @@ -104,7 +104,7 @@ namespace XivCommon.Functions { try { this.OnChatBubble?.Invoke(ref actor, ref text); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in chat bubble event"); + Logger.LogError(ex, "Exception in chat bubble event"); } var newText = text.Encode().Terminate(); @@ -120,7 +120,7 @@ namespace XivCommon.Functions { try { this.UpdateChatBubbleDetourInner(bubble, actor, a3); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in update chat bubble detour"); + Logger.LogError(ex, "Exception in update chat bubble detour"); this.UpdateChatBubbleHook!.Original(bubble, actor, a3); } } @@ -132,7 +132,7 @@ namespace XivCommon.Functions { try { this.OnUpdateBubble?.Invoke(ref actor); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in chat bubble update event"); + Logger.LogError(ex, "Exception in chat bubble update event"); } this.UpdateChatBubbleHook!.Original(bubble, actor.Address, a3); diff --git a/XivCommon/Functions/PartyFinder.cs b/XivCommon/Functions/PartyFinder.cs index 9ca3e45..ec42387 100755 --- a/XivCommon/Functions/PartyFinder.cs +++ b/XivCommon/Functions/PartyFinder.cs @@ -121,7 +121,7 @@ namespace XivCommon.Functions { this.JoinParty?.Invoke(listing); } } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in PF join detour"); + Logger.LogError(ex, "Exception in PF join detour"); } return ret; diff --git a/XivCommon/Functions/Talk.cs b/XivCommon/Functions/Talk.cs index 54ce912..c285854 100755 --- a/XivCommon/Functions/Talk.cs +++ b/XivCommon/Functions/Talk.cs @@ -77,7 +77,7 @@ namespace XivCommon.Functions { try { this.AddonTalkV45DetourInner(data); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in Talk detour"); + Logger.LogError(ex, "Exception in Talk detour"); } Return: @@ -95,7 +95,7 @@ namespace XivCommon.Functions { try { this.OnTalk?.Invoke(ref name, ref text, ref style); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in Talk event"); + Logger.LogError(ex, "Exception in Talk event"); } var newName = name.Encode().Terminate(); diff --git a/XivCommon/Logger.cs b/XivCommon/Logger.cs new file mode 100755 index 0000000..814f01a --- /dev/null +++ b/XivCommon/Logger.cs @@ -0,0 +1,26 @@ +using System; +using Dalamud.Plugin; + +namespace XivCommon { + internal static class Logger { + private static string Format(string msg) { + return $"[XIVCommon] {msg}"; + } + + internal static void Log(string msg) { + PluginLog.Log(Format(msg)); + } + + internal static void LogWarning(string msg) { + PluginLog.LogWarning(Format(msg)); + } + + internal static void LogError(string msg) { + PluginLog.LogError(Format(msg)); + } + + internal static void LogError(Exception ex, string msg) { + PluginLog.LogError(ex, Format(msg)); + } + } +} diff --git a/XivCommon/Util.cs b/XivCommon/Util.cs index 314e42e..4c3fceb 100755 --- a/XivCommon/Util.cs +++ b/XivCommon/Util.cs @@ -29,7 +29,7 @@ namespace XivCommon { } internal static void PrintMissingSig(string name) { - PluginLog.LogWarning($"Could not find signature for {name}. This functionality will be disabled."); + Logger.LogWarning($"Could not find signature for {name}. This functionality will be disabled."); } } }