Skip to content

Commit 62d9428

Browse files
committed
Add logger pausing and resuming, fix the log file read issue
1 parent 0932c48 commit 62d9428

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

Runtime/Scripts/BugReportUI.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,26 @@ void OnDestroy()
645645
// Cleanup handled automatically since we don't subscribe to events
646646
}
647647

648+
public static void PauseLogger()
649+
{
650+
#if !DISABLE_BETAHUB_LOGGER
651+
if (_logger != null)
652+
{
653+
_logger.PauseLogging();
654+
}
655+
#endif
656+
}
657+
658+
public static void ResumeLogger()
659+
{
660+
#if !DISABLE_BETAHUB_LOGGER
661+
if (_logger != null)
662+
{
663+
_logger.ResumeLogging();
664+
}
665+
#endif
666+
}
667+
648668
private void ValidateProviderCustomFields()
649669
{
650670
// Skip validation if we don't have the necessary credentials

Runtime/Scripts/Issue.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,34 @@ private IEnumerator PostVideo(GameRecorder gameRecorder)
409409

410410
private IEnumerator UploadFile(string endpoint, string fieldName, string filePath, string contentType)
411411
{
412+
bool isLogFile = Path.GetExtension(filePath).Equals(".log", StringComparison.OrdinalIgnoreCase);
413+
if (isLogFile)
414+
{
415+
BugReportUI.PauseLogger();
416+
yield return new WaitForSeconds(0.1f);
417+
}
418+
419+
byte[] fileData;
420+
try
421+
{
422+
fileData = File.ReadAllBytes(filePath);
423+
}
424+
catch (Exception ex)
425+
{
426+
Debug.LogError($"Error reading file {filePath}: {ex.Message}");
427+
if (isLogFile)
428+
{
429+
BugReportUI.ResumeLogger();
430+
}
431+
yield break;
432+
}
433+
434+
if (isLogFile)
435+
{
436+
BugReportUI.ResumeLogger();
437+
}
438+
412439
WWWForm form = new WWWForm();
413-
byte[] fileData = File.ReadAllBytes(filePath);
414440
form.AddBinaryData(fieldName, fileData, Path.GetFileName(filePath), contentType);
415441

416442
string url = $"{_betahubEndpoint}projects/{_projectId}/issues/g-{Id}/{endpoint}";

Runtime/Scripts/Logger.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,38 @@ public void ForceFlush()
124124
}
125125
}
126126

127+
public void PauseLogging()
128+
{
129+
lock (lockObject)
130+
{
131+
FlushBuffer();
132+
writer?.Dispose();
133+
fileStream?.Dispose();
134+
writer = null;
135+
fileStream = null;
136+
}
137+
}
138+
139+
public void ResumeLogging()
140+
{
141+
lock (lockObject)
142+
{
143+
if (writer == null && fileStream == null)
144+
{
145+
try
146+
{
147+
// Append to existing file instead of recreating it
148+
fileStream = new FileStream(_logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
149+
writer = new StreamWriter(fileStream) { AutoFlush = false };
150+
}
151+
catch (Exception e)
152+
{
153+
Debug.LogError("Error resuming log file stream: " + e.Message);
154+
}
155+
}
156+
}
157+
}
158+
127159
public void Dispose()
128160
{
129161
if (disposed) return;

0 commit comments

Comments
 (0)