Skip to content

Commit

Permalink
add more debug logging, fixed a few typos
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSav committed May 6, 2024
1 parent 2ab3bcb commit d4ea225
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 287 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Changelog


## 0.0.4 (unreleased)
## 0.0.5 (unreleased)
- Add ability to hide already looted items for those item, where it can be detected - work in progress
- Add ability to hide items unobtainable in the current run without reroll - work in progress
- Add more debug logging - work in progress
- Fixed a few typos

## 0.0.4 (6 May 2024)
- Add option to log save data for debugging purposes
- Add option to dump analyzer data structures in json for debugging purposes
- Add option to log performance metrics for debugging purposes
- Fixed a few typos

## 0.0.3 (3 May 2024)

Expand Down
9 changes: 9 additions & 0 deletions Remnant2SaveAnalyzer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@
<setting name="ShowItemsWithNoPrerequisites" serializeAs="String">
<value>True</value>
</setting>
<setting name="ReportPerformance" serializeAs="String">
<value>False</value>
</setting>
<setting name="ReportPlayerInfo" serializeAs="String">
<value>False</value>
</setting>
<setting name="DumpAnalyzerJson" serializeAs="String">
<value>False</value>
</setting>
</Remnant2SaveAnalyzer.Properties.Settings>
</userSettings>
</configuration>
218 changes: 109 additions & 109 deletions Remnant2SaveAnalyzer/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,111 +1,111 @@
using Remnant2SaveAnalyzer.Views.Windows;
using System;
using System.Collections.Generic;
using System.IO;

namespace Remnant2SaveAnalyzer
{
internal static class Logger
{
public static event EventHandler<MessageLoggedEventArgs>? MessageLogged;

static Logger()
{
if (Properties.Settings.Default.CreateLogFile)
{
CreateLog();
}
Properties.Settings.Default.PropertyChanged += Default_PropertyChanged;
}

public static List<LogMessage> Messages { get; } = [];

private static void Default_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName != "CreateLogFile")
{
return;
}
if (!Properties.Settings.Default.CreateLogFile)
{
return;
}
CreateLog();
}

private static void CreateLog()
{
File.WriteAllText("log.txt", DateTime.Now + ": Version " + typeof(MainWindow).Assembly.GetName().Version + "\r\n");
}

public static void Log(object? message, LogType logType, bool silent = false)
{
message ??= "null";
if (!silent)
{
MessageLogged?.Invoke(null, new(message.ToString() ?? "", logType));
}
Messages.Add(new(message.ToString() ?? "", logType));
if (Properties.Settings.Default.CreateLogFile)
{
StreamWriter writer = File.AppendText("log.txt");
writer.WriteLine($"{DateTime.Now}[{logType}]: {message}");
writer.Close();
}
//Debug.WriteLine(message);
}

public static void Log(object message)
{
Log(message, LogType.Normal);
using Remnant2SaveAnalyzer.Views.Windows;
using System;
using System.Collections.Generic;
using System.IO;

namespace Remnant2SaveAnalyzer
{
internal static class Logger
{
public static event EventHandler<MessageLoggedEventArgs>? MessageLogged;

static Logger()
{
if (Properties.Settings.Default.CreateLogFile)
{
CreateLog();
}
Properties.Settings.Default.PropertyChanged += Default_PropertyChanged;
}

public static List<LogMessage> Messages { get; } = [];

private static void Default_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName != "CreateLogFile")
{
return;
}
if (!Properties.Settings.Default.CreateLogFile)
{
return;
}
CreateLog();
}

public static void LogSilent(object message)
{
Log(message, LogType.Normal, true);
}

public static void Success(object message)
{
Log(message, LogType.Success);
}

public static void Error(object message)
{
Log(message, LogType.Error);
}

public static void Warn(object message)
{
Log(message, LogType.Warning);
}

public static void WarnSilent(string message)
{
Log(message, LogType.Warning, true);
}
}

public enum LogType
{
Normal,
Success,
Error,
Warning,
}

public class MessageLoggedEventArgs(string message, LogType logType) : EventArgs
{
public string Message { get; set; } = message;
public LogType LogType { get; set;} = logType;

public MessageLoggedEventArgs(string message) : this(message, LogType.Normal)
{
}
}
public class LogMessage(string message, LogType logType)
{
public string Message { get; set; } = message;
public LogType LogType { get; set; } = logType;
}
}
private static void CreateLog()
{
File.WriteAllText("log.txt", DateTime.Now + ": Version " + typeof(MainWindow).Assembly.GetName().Version + "\r\n");
}

public static void Log(object? message, LogType logType, bool silent = false)
{
message ??= "null";
if (!silent)
{
MessageLogged?.Invoke(null, new(message.ToString() ?? "", logType));
}
Messages.Add(new(message.ToString() ?? "", logType));
if (Properties.Settings.Default.CreateLogFile)
{
StreamWriter writer = File.AppendText("log.txt");
writer.WriteLine($"{DateTime.Now} [{logType}]: {message}");
writer.Close();
}
//Debug.WriteLine(message);
}

public static void Log(object message)
{
Log(message, LogType.Normal);
}

public static void LogSilent(object message)
{
Log(message, LogType.Normal, true);
}

public static void Success(object message)
{
Log(message, LogType.Success);
}

public static void Error(object message)
{
Log(message, LogType.Error);
}

public static void Warn(object message)
{
Log(message, LogType.Warning);
}

public static void WarnSilent(string message)
{
Log(message, LogType.Warning, true);
}
}

public enum LogType
{
Normal,
Success,
Error,
Warning,
}

public class MessageLoggedEventArgs(string message, LogType logType) : EventArgs
{
public string Message { get; set; } = message;
public LogType LogType { get; set;} = logType;

public MessageLoggedEventArgs(string message) : this(message, LogType.Normal)
{
}
}
public class LogMessage(string message, LogType logType)
{
public string Message { get; set; } = message;
public LogType LogType { get; set; } = logType;
}
}
36 changes: 36 additions & 0 deletions Remnant2SaveAnalyzer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Remnant2SaveAnalyzer/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,14 @@
<Setting Name="ShowItemsWithNoPrerequisites" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="ReportPerformance" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ReportPlayerInfo" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="DumpAnalyzerJson" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion Remnant2SaveAnalyzer/Remnant2SaveAnalyzer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="lib.remnant2.analyzer" Version="0.0.3" />
<PackageReference Include="lib.remnant2.analyzer" Version="0.0.5" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.IO.Hashing" Version="8.0.0" />
Expand Down
Loading

0 comments on commit d4ea225

Please sign in to comment.