Log watcher init after browser

This commit is contained in:
Natsumi
2025-06-26 19:01:18 +12:00
parent 028dffe38c
commit d751a89501
2 changed files with 30 additions and 23 deletions
+24 -16
View File
@@ -33,8 +33,9 @@ namespace VRCX
private ReaderWriterLockSlim m_LogListLock; private ReaderWriterLockSlim m_LogListLock;
private bool m_FirstRun = true; private bool m_FirstRun = true;
private bool m_ResetLog; private bool m_ResetLog;
private Thread m_Thread; private bool threadActive;
private DateTime tillDate = DateTime.UtcNow; private Thread? m_Thread;
private DateTime tillDate;
public bool VrcClosedGracefully; public bool VrcClosedGracefully;
private readonly ConcurrentQueue<string> m_LogQueue = new ConcurrentQueue<string>(); // for electron private readonly ConcurrentQueue<string> m_LogQueue = new ConcurrentQueue<string>(); // for electron
@@ -62,6 +63,7 @@ namespace VRCX
public void Exit() public void Exit()
{ {
threadActive = false;
var thread = m_Thread; var thread = m_Thread;
m_Thread = null; m_Thread = null;
thread.Interrupt(); thread.Interrupt();
@@ -77,6 +79,7 @@ namespace VRCX
public void SetDateTill(string date) public void SetDateTill(string date)
{ {
tillDate = DateTime.Parse(date, CultureInfo.InvariantCulture, DateTimeStyles.None).ToUniversalTime(); tillDate = DateTime.Parse(date, CultureInfo.InvariantCulture, DateTimeStyles.None).ToUniversalTime();
threadActive = true;
logger.Info("SetDateTill: {0}", tillDate.ToLocalTime()); logger.Info("SetDateTill: {0}", tillDate.ToLocalTime());
} }
@@ -84,6 +87,7 @@ namespace VRCX
{ {
while (m_Thread != null) while (m_Thread != null)
{ {
if (threadActive)
Update(); Update();
try try
@@ -130,15 +134,11 @@ namespace VRCX
foreach (var fileInfo in fileInfos) foreach (var fileInfo in fileInfos)
{ {
fileInfo.Refresh(); fileInfo.Refresh();
if (fileInfo.Exists == false) if (!fileInfo.Exists)
{
continue; continue;
}
if (DateTime.Compare(fileInfo.LastWriteTimeUtc, tillDate) < 0) if (DateTime.Compare(fileInfo.LastWriteTimeUtc, tillDate) < 0)
{
continue; continue;
}
if (m_LogContextMap.TryGetValue(fileInfo.Name, out var logContext)) if (m_LogContextMap.TryGetValue(fileInfo.Name, out var logContext))
{ {
@@ -151,9 +151,7 @@ namespace VRCX
} }
if (logContext.Length == fileInfo.Length) if (logContext.Length == fileInfo.Length)
{
continue; continue;
}
logContext.Length = fileInfo.Length; logContext.Length = fileInfo.Length;
ParseLog(fileInfo, logContext); ParseLog(fileInfo, logContext);
@@ -491,14 +489,19 @@ namespace VRCX
return true; return true;
var userInfo = ParseUserInfo(line.Substring(lineOffset)); var userInfo = ParseUserInfo(line.Substring(lineOffset));
if (string.IsNullOrEmpty(userInfo.DisplayName) && string.IsNullOrEmpty(userInfo.UserId))
{
logger.Warn("Failed to parse user info from log line: {0}", line);
return true;
}
AppendLog(new[] AppendLog(new[]
{ {
fileInfo.Name, fileInfo.Name,
ConvertLogTimeToISO8601(line), ConvertLogTimeToISO8601(line),
"player-joined", "player-joined",
userInfo.DisplayName, userInfo.DisplayName ?? string.Empty,
userInfo.UserId userInfo.UserId ?? string.Empty
}); });
return true; return true;
@@ -514,14 +517,19 @@ namespace VRCX
return true; return true;
var userInfo = ParseUserInfo(line.Substring(lineOffset)); var userInfo = ParseUserInfo(line.Substring(lineOffset));
if (string.IsNullOrEmpty(userInfo.DisplayName) && string.IsNullOrEmpty(userInfo.UserId))
{
logger.Warn("Failed to parse user info from log line: {0}", line);
return true;
}
AppendLog(new[] AppendLog(new[]
{ {
fileInfo.Name, fileInfo.Name,
ConvertLogTimeToISO8601(line), ConvertLogTimeToISO8601(line),
"player-left", "player-left",
userInfo.DisplayName, userInfo.DisplayName ?? string.Empty,
userInfo.UserId userInfo.UserId ?? string.Empty
}); });
return true; return true;
@@ -1392,10 +1400,10 @@ namespace VRCX
return new string[][] { }; return new string[][] { };
} }
private static (string DisplayName, string UserId) ParseUserInfo(string userInfo) private static (string? DisplayName, string? UserId) ParseUserInfo(string userInfo)
{ {
string userDisplayName; string? userDisplayName;
string userId; string? userId;
int pos = userInfo.LastIndexOf(" (", StringComparison.Ordinal); int pos = userInfo.LastIndexOf(" (", StringComparison.Ordinal);
if (pos >= 0) if (pos >= 0)
-1
View File
@@ -951,7 +951,6 @@ export default class extends baseClass {
async updateGameLog(dateTill) { async updateGameLog(dateTill) {
await gameLogService.setDateTill(dateTill); await gameLogService.setDateTill(dateTill);
await gameLogService.reset();
await new Promise((resolve) => { await new Promise((resolve) => {
workerTimers.setTimeout(resolve, 10000); workerTimers.setTimeout(resolve, 10000);
}); });