about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared/LogView.razor
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-01-24 02:31:56 +0100
committerRory& <root@rory.gay>2024-01-24 17:05:25 +0100
commit03313562d21d5db9bf6a14ebbeab80e06c883d3a (patch)
treee000546a2ee8e6a886a7ed9fd01ad674178fb7cb /MatrixUtils.Web/Shared/LogView.razor
parentMake RMU installable (diff)
downloadMatrixUtils-03313562d21d5db9bf6a14ebbeab80e06c883d3a.tar.xz
MRU->RMU, fixes, cleanup
Diffstat (limited to 'MatrixUtils.Web/Shared/LogView.razor')
-rw-r--r--MatrixUtils.Web/Shared/LogView.razor41
1 files changed, 41 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Shared/LogView.razor b/MatrixUtils.Web/Shared/LogView.razor
new file mode 100644
index 0000000..d541b82
--- /dev/null
+++ b/MatrixUtils.Web/Shared/LogView.razor
@@ -0,0 +1,41 @@
+@* @using System.Text *@
+@* @if (LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers) { *@
+@*     <u>Logs</u> *@
+@*     <br/> *@
+@*     <pre> *@
+@*         @_stringBuilder *@
+@*     </pre> *@
+@* } *@
+@* *@
+@* @code { *@
+@*     StringBuilder _stringBuilder = new(); *@
+@* *@
+@*     protected override async Task OnInitializedAsync() { *@
+@*         if (!LocalStorageWrapper.Settings.DeveloperSettings.EnableConsoleLogging) { *@
+@*             Console.WriteLine("Console logging disabled!"); *@
+@*             var _sw = new StringWriter(); *@
+@*             Console.SetOut(_sw); *@
+@*             Console.SetError(_sw); *@
+@*             return; *@
+@*         } *@
+@*         if (!LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers) return; *@
+@*     //intecept stdout with textwriter to get logs *@
+@*         var sw = new StringWriter(_stringBuilder); *@
+@*         Console.SetOut(sw); *@
+@*         Console.SetError(sw); *@
+@*     //keep updated *@
+@*         var length = 0; *@
+@*         Task.Run(async () => { *@
+@*             while (true) { *@
+@*                 await Task.Delay(100); *@
+@*                 if (_stringBuilder.Length != length) { *@
+@*                     StateHasChanged(); *@
+@*                     length = _stringBuilder.Length; *@
+@*                 } *@
+@*             } *@
+@*     // ReSharper disable once FunctionNeverReturns - This is intentional behavior *@
+@*         }); *@
+@*         await base.OnInitializedAsync(); *@
+@*     } *@
+@* *@
+@* } *@
\ No newline at end of file