Skip to content

Commit

Permalink
log everything into Dalamud.Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
marzent committed Mar 25, 2023
1 parent c36850f commit 720c56f
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 110 deletions.
10 changes: 5 additions & 5 deletions IINACT/FfxivActPluginWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using Dalamud.Game.Gui;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Logging;
using FFXIV_ACT_Plugin;
using FFXIV_ACT_Plugin.Common;
using FFXIV_ACT_Plugin.Config;
using FFXIV_ACT_Plugin.Logfile;
using FFXIV_ACT_Plugin.Memory;
using FFXIV_ACT_Plugin.Memory.MemoryReader;
using FFXIV_ACT_Plugin.Parse;
using FFXIV_ACT_Plugin.Resource;
using Machina.FFXIV;
Expand Down Expand Up @@ -108,9 +108,6 @@ private void SetupSettingsMediator()
};
settingsMediator.DataCollectionSettings = DataCollectionSettings;

var readProcesses = ProcessManager.GetField<ReadProcesses>("_readProcesses");
readProcesses.Read64(true);

ParseSettings = new ParseSettings
{
DisableDamageShield = configuration.DisableDamageShield,
Expand Down Expand Up @@ -188,5 +185,8 @@ private static void OnZoneChanged(uint zoneId, string zoneName)
ActGlobals.oFormActMain.ChangeZone(zoneName);
}

private static void OnProcessException(DateTime timestamp, string text) { }
private static void OnProcessException(DateTime timestamp, string text)
{
PluginLog.Error($"[FFXIV_ACT_PLUGIN] Exception: {text}");
}
}
7 changes: 7 additions & 0 deletions IINACT/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using Dalamud.Data;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
Expand Down Expand Up @@ -36,9 +37,13 @@ public sealed class Plugin : IDalamudPlugin
private FfxivActPluginWrapper FfxivActPluginWrapper { get; init; }
private RainbowMage.OverlayPlugin.PluginMain OverlayPlugin { get; set; }
internal string OverlayPluginStatus => OverlayPlugin.Status;
private PluginLogTraceListener PluginLogTraceListener { get; init; }

public Plugin()
{
PluginLogTraceListener = new PluginLogTraceListener();
Trace.Listeners.Add(PluginLogTraceListener);

FileDialogManager = new FileDialogManager();
Machina.FFXIV.Dalamud.DalamudClient.GameNetwork = GameNetwork;

Expand Down Expand Up @@ -82,6 +87,7 @@ public void Dispose()
{
FfxivActPluginWrapper.Dispose();
OverlayPlugin.DeInitPlugin();
Trace.Listeners.Remove(PluginLogTraceListener);

WindowSystem.RemoveAllWindows();

Expand Down Expand Up @@ -124,6 +130,7 @@ private RainbowMage.OverlayPlugin.PluginMain InitOverlayPlugin()
private void OnCommand(string command, string args)
{
MainWindow.IsOpen = true;
FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.GetServerTime();
}

private static void EndEncounter(string command, string args)
Expand Down
25 changes: 25 additions & 0 deletions IINACT/PluginLogTraceListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Diagnostics;
using Dalamud.Logging;

namespace IINACT;

public class PluginLogTraceListener : TraceListener
{
public override void Write(string? message) { }

public override void WriteLine(string? message) { }

public override void WriteLine(string? message, string? category)
{
if (message is null) return;

if (category?.Equals("ffxiv_act_plugin", StringComparison.OrdinalIgnoreCase) ?? false)
PluginLog.Information($"[FFXIV_ACT_PLUGIN] {message}");

if (category?.Equals("machina", StringComparison.OrdinalIgnoreCase) ?? false)
PluginLog.Information($"[MACHINA] {message}");

if (category?.Equals("debug-machina", StringComparison.OrdinalIgnoreCase) ?? false)
PluginLog.Debug($"[MACHINA] {message}");
}
}
11 changes: 6 additions & 5 deletions IINACT/TextToSpeechProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Speech.Synthesis;
using System.Text.RegularExpressions;
using Dalamud.Logging;

namespace IINACT;

Expand All @@ -20,7 +21,7 @@ public TextToSpeechProvider()
}
catch (Exception ex)
{
Trace.WriteLine(ex, $"Failed to initialize SAPI TTS engine {ex.Message}");
PluginLog.Warning(ex, "Failed to initialize SAPI TTS engine");
}

Advanced_Combat_Tracker.ActGlobals.oFormActMain.TextToSpeech += Speak;
Expand All @@ -36,10 +37,10 @@ public void Speak(string message)
{
StartInfo =
{
FileName = binary,
FileName = "C:\\windows\\system32\\start.exe",
CreateNoWindow = true,
UseShellExecute = false,
Arguments = args + " \"" +
Arguments = $"/unix {binary} {args} \"" +
Regex.Replace(Regex.Replace(message, @"(\\*)" + "\"", @"$1$1\" + "\""),
@"(\\+)$", @"$1$1") + "\""
}
Expand All @@ -55,7 +56,7 @@ public void Speak(string message)
}
catch (Exception ex)
{
Trace.WriteLine(ex, $"TTS failed to play back {message} with exception {ex.Message}");
PluginLog.Error(ex, $"TTS failed to play back {message}");
return;
}
}
Expand All @@ -67,7 +68,7 @@ public void Speak(string message)
}
catch (Exception ex)
{
Trace.WriteLine(ex, $"TTS failed to play back {message} with exception {ex.Message}");
PluginLog.Error(ex, $"TTS failed to play back {message}");
}

}
Expand Down
9 changes: 3 additions & 6 deletions NotACT/FormActMain.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Media;
using System.Text.RegularExpressions;
using Advanced_Combat_Tracker.Resources;
using Dalamud.Logging;
using FFXIV_ACT_Plugin.Logfile;

namespace Advanced_Combat_Tracker;
Expand Down Expand Up @@ -118,11 +118,8 @@ public event LogFileChangedDelegate LogFileChanged
public event TextToSpeechDelegate TextToSpeech;


public void WriteExceptionLog(Exception ex, string MoreInfo)
{
var value = $"***** {DateTime.Now:s} - {MoreInfo}\n{ex}\n{Environment.StackTrace}\n*****";
Trace.WriteLine(value);
}
public void WriteExceptionLog(Exception ex, string MoreInfo) =>
PluginLog.Error(ex, MoreInfo);

public void OpenLog(bool GetCurrentZone, bool GetCharNameFromFile) { }

Expand Down
22 changes: 21 additions & 1 deletion NotACT/NotACT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
<Folder Include="Datatypes\"/>
</ItemGroup>

<PropertyGroup>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup>

<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'">
<DalamudLibPath>$(HOME)/Library/Application Support/XIV on Mac/dalamud/Hooks/dev/</DalamudLibPath>
</PropertyGroup>

<ItemGroup>
<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>

<ItemGroup>
<Reference Include="FFXIV_ACT_Plugin">
<HintPath>..\external_dependencies\FFXIV_ACT_Plugin.dll</HintPath>
Expand All @@ -31,4 +51,4 @@
</Reference>
</ItemGroup>

</Project>
</Project>
1 change: 0 additions & 1 deletion OverlayPlugin.Common/OverlayConfigList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void ReadXml(System.Xml.XmlReader reader)
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e);
_logger.Log(LogLevel.Error, e.ToString());
}
}
Expand Down
41 changes: 19 additions & 22 deletions OverlayPlugin.Core/EventSources/CactbotEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,35 +209,32 @@ public override void Start()

language = ffxivRepository.GetLocaleString();
pcLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;

var overlay = typeof(IOverlay).Assembly.GetName().Version!;
var ffxivPluginVersion = ffxivRepository.GetPluginVersion();
var act = typeof(ActGlobals).Assembly.GetName().Version!;

var actVersion = typeof(ActGlobals).Assembly.GetName().Version!;

// Print out version strings and locations to help users debug.
LogInfo("OverlayPlugin: {0} {1}", overlay.ToString(), typeof(IOverlay).Assembly.Location);
LogInfo("FFXIV Plugin: {0} {1}", ffxivPluginVersion.ToString(), ffxivRepository.GetPluginPath());
LogInfo("ACT: {0} {1}", act.ToString(), typeof(ActGlobals).Assembly.Location);
LogInfo("OverlayPlugin Version: {0}", ffxivRepository.GetOverlayPluginVersion().ToString());
LogInfo("FFXIV Plugin Version: {0}", ffxivRepository.GetPluginVersion().ToString());
LogInfo("ACT Version: {0}", actVersion.ToString());

LogInfo("Parsing Plugin Language: {0}", language ?? "(unknown)");

LogInfo("System Locale: {0}", pcLocale ?? "(unknown)");

// Temporarily target cn if plugin is old v2.0.4.0
if (language == "cn" || ffxivPluginVersion.ToString() == "2.0.4.0")
{
this.ffxiv = new FFXIVProcessCn(container);
LogInfo("Version: cn");
}
else if (language == "ko")
{
this.ffxiv = new FFXIVProcessKo(container);
LogInfo("Version: ko");
}
else
{
this.ffxiv = new FFXIVProcessIntl(container);
LogInfo("Version: intl");
switch (language)
{
case "cn":
this.ffxiv = new FFXIVProcessCn(container);
LogInfo("Version: cn");
break;
case "ko":
this.ffxiv = new FFXIVProcessKo(container);
LogInfo("Version: ko");
break;
default:
this.ffxiv = new FFXIVProcessIntl(container);
LogInfo("Version: intl");
break;
}

// Incoming events.
Expand Down
3 changes: 1 addition & 2 deletions OverlayPlugin.Core/EventSources/MiniParseEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Advanced_Combat_Tracker;
using Newtonsoft.Json.Linq;
using RainbowMage.OverlayPlugin.WebSocket;
Expand Down Expand Up @@ -292,7 +291,7 @@ internal JObject CreateCombatData()

#if DEBUG
stopwatch.Stop();
Log(LogLevel.Trace, "CreateUpdateScript: {0} msec", stopwatch.Elapsed.TotalMilliseconds);
PluginLog.Verbose("CreateUpdateScript: {0} msec", stopwatch.Elapsed.TotalMilliseconds);
#endif
return obj;
}
Expand Down
3 changes: 1 addition & 2 deletions OverlayPlugin.Core/Integration/FFXIVRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Advanced_Combat_Tracker;
using FFXIV_ACT_Plugin.Common;
using FFXIV_ACT_Plugin.Logfile;
using Machina;
using Machina.FFXIV;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -175,7 +174,7 @@ public Version GetOverlayPluginVersion()

public Version GetPluginVersion()
{
return typeof(IDataRepository).Assembly.GetName().Version;
return typeof(FFXIV_ACT_Plugin.FFXIV_ACT_Plugin).Assembly.GetName().Version;
}

public string GetPluginPath()
Expand Down
Loading

0 comments on commit 720c56f

Please sign in to comment.