Skip to content

Commit 2900a6c

Browse files
committed
Fixed minidumps and extra logging options
1 parent 2bfa445 commit 2900a6c

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

‎Torch.API/ITorchConfig.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public interface ITorchConfig
3030
int FontSize { get; set; }
3131
UGCServiceType UgcServiceType { get; set; }
3232
TorchBranchType BranchName { get; set; }
33+
bool SendLogsToKeen { get; set; }
34+
bool DeleteMiniDumps { get; set; }
3335

3436
void Save(string path = null);
3537
}

‎Torch.Server/Initializer.cs‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
using System.Windows.Threading;
1414
using NLog;
1515
using NLog.Targets;
16+
using Sandbox;
1617
using Sandbox.Engine.Utils;
1718
using Torch.Utils;
19+
using VRage;
1820
using VRage.FileSystem;
21+
using VRage.Scripting;
22+
using VRage.Utils;
1923

2024
namespace Torch.Server
2125
{
@@ -60,6 +64,7 @@ public bool Initialize(string[] args)
6064
#endif
6165

6266
#if DEBUG
67+
AppDomain.CurrentDomain.UnhandledException += HandleException;
6368
//enables logging debug messages when built in debug mode. Amazing.
6469
LogManager.Configuration.AddRule(LogLevel.Debug, LogLevel.Debug, "main");
6570
LogManager.Configuration.AddRule(LogLevel.Debug, LogLevel.Debug, "console");
@@ -255,19 +260,37 @@ private void LogException(Exception ex)
255260
}
256261
}
257262

263+
private void SendAndDump()
264+
{
265+
var shortdate = DateTime.Now.ToString("yyyy-MM-dd");
266+
var shortdateWithTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
267+
268+
var dumpPath = $"Logs\\MiniDumpT{Thread.CurrentThread.ManagedThreadId}-{shortdateWithTime}.dmp";
269+
Log.Info($"Generating minidump at {dumpPath}");
270+
var dumpFlags = MyMiniDump.Options.Normal | MyMiniDump.Options.WithProcessThreadData | MyMiniDump.Options.WithThreadInfo;
271+
MyVRage.Platform.CrashReporting.WriteMiniDump(dumpPath, dumpFlags, IntPtr.Zero);
272+
273+
if (Config.SendLogsToKeen)
274+
{
275+
List<string> additionalFiles = new List<string>();
276+
if (File.Exists(dumpPath))
277+
additionalFiles.Add(dumpPath);
278+
279+
CrashInfo info = MyErrorReporter.BuildCrashInfo();
280+
MyErrorReporter.ReportNotInteractive($"Logs\\Keen-{shortdate}.log", info.AnalyticId, false,
281+
additionalFiles.ToList(), true, string.Empty, string.Empty, info);
282+
}
283+
284+
if(Config.DeleteMiniDumps)
285+
File.Delete(dumpPath);
286+
}
287+
258288
private void HandleException(object sender, UnhandledExceptionEventArgs e)
259289
{
260290
_server.FatalException = true;
261291
var ex = (Exception)e.ExceptionObject;
262292
LogException(ex);
263-
if (MyFakes.ENABLE_MINIDUMP_SENDING)
264-
{
265-
string path = Path.Combine(MyFileSystem.UserDataPath, "Minidump.dmp");
266-
Log.Info($"Generating minidump at {path}");
267-
Log.Error("Keen broke the minidump, sorry.");
268-
//MyMiniDump.Options options = MyMiniDump.Options.WithProcessThreadData | MyMiniDump.Options.WithThreadInfo;
269-
//MyMiniDump.Write(path, options, MyMiniDump.ExceptionInfo.Present);
270-
}
293+
SendAndDump();
271294
LogManager.Flush();
272295
if (Config.RestartOnCrash)
273296
{

‎Torch.Server/TorchConfig.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class TorchConfig : CommandLine, ITorchConfig, INotifyPropertyChanged
4242
private int _fontSize = 16;
4343
private UGCServiceType _ugcServiceType = UGCServiceType.Steam;
4444
private TorchBranchType _torchBranch = TorchBranchType.master;
45+
private bool _sendLogsToKeen;
46+
private bool _deleteMiniDumps = true;
4547

4648

4749
/// <inheritdoc />
@@ -169,6 +171,16 @@ public TorchBranchType BranchName
169171
[Arg("asserts", "Enable Keen's assert logging.")]
170172
[Display(Name = "Enable Asserts", Description = "Enable Keen's assert logging.", GroupName = "Server")]
171173
public bool EnableAsserts { get => _enableAsserts; set => Set(value, ref _enableAsserts); }
174+
175+
[Arg("sendlogstokeen", "On crash, send debug data and logs to Keen.")]
176+
[Display(Name = "Send Logs To Keen", Description = "On crash, send debug data and logs to Keen.", GroupName = "Logging")]
177+
public bool SendLogsToKeen { get => _sendLogsToKeen; set => Set(value, ref _sendLogsToKeen); }
178+
179+
[Arg("delteminidumps", "Delete mini dumps after they are created")]
180+
[Display(Name = "Delete Mini Dumps", Description = "Delete mini dumps after they are created", GroupName = "Logging")]
181+
public bool DeleteMiniDumps { get => _deleteMiniDumps; set => Set(value, ref _deleteMiniDumps); }
182+
183+
172184

173185
public event PropertyChangedEventHandler PropertyChanged;
174186

‎Torch.Server/TorchServer.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using NLog;
1313
using Sandbox;
1414
using Sandbox.Engine.Networking;
15+
using Sandbox.Game;
1516
using Sandbox.Game.Multiplayer;
1617
using Sandbox.Game.World;
1718
using Torch.API;
@@ -167,6 +168,7 @@ public override void Start()
167168
CanRun = false;
168169
PatchManager.CommitInternal();
169170
Log.Info("Starting server.");
171+
MyPerGameSettings.BasicGameInfo.AnalyticId = "SEDS_TORCH";
170172
MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model;
171173

172174
_uptime = Stopwatch.StartNew();

0 commit comments

Comments
 (0)