-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from unyt-org/feat-debug-pages
Add web debug interface pages (network and logs)
- Loading branch information
Showing
9 changed files
with
256 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Datex } from "datex-core-legacy/mod.ts"; | ||
import { LOG_LEVEL } from "datex-core-legacy/utils/logger.ts"; | ||
|
||
@endpoint export class DebugLogs { | ||
@property static getLogs() { | ||
|
||
const timeout = 60; // 60 minutes | ||
|
||
const stream = $$(new Datex.Stream<string|ArrayBuffer>()); | ||
Datex.Logger.logToStream(stream); | ||
|
||
// close stream after timeout | ||
setTimeout(() => { | ||
// \u0004 is the EOT character | ||
stream.write(new TextEncoder().encode("\n[Stream was closed after " + timeout + " minutes]\n\u0004").buffer); | ||
stream.close(); | ||
}, timeout * 60 * 1000); | ||
|
||
return stream; | ||
} | ||
|
||
@property static enableMessageLogger() { | ||
enableMessageLogger() | ||
} | ||
|
||
@property static disableMessageLogger() { | ||
disableMessageLogger() | ||
} | ||
|
||
@property static enableVerboseLogs() { | ||
Datex.Logger.production_log_level = LOG_LEVEL.VERBOSE | ||
Datex.Logger.development_log_level = LOG_LEVEL.VERBOSE | ||
} | ||
|
||
@property static disableVerboseLogs() { | ||
Datex.Logger.production_log_level = LOG_LEVEL.DEFAULT | ||
Datex.Logger.development_log_level = LOG_LEVEL.DEFAULT | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { DebugLogs } from "./logs-backend.ts"; | ||
import { app } from "../app.ts" | ||
import { convertANSIToHTML } from "../../utils/ansi-to-html.ts"; | ||
import { unsafeHTML } from "../../html/unsafe-html.ts"; | ||
|
||
const messageLoggerEnabled = $$(false); | ||
const verboseLogsEnabled = $$(false); | ||
|
||
const logsContainer = <div style="width:100%;overflow:scroll;"></div> | ||
const component = <div style="height:100vh;overflow: hidden;padding:20px;display: flex;flex-direction: column;"> | ||
<div style="user-select: none;margin-bottom:10px;padding:10px;background:var(--bg-content);border-radius:10px;display:flex;gap:10px;align-items: center;"> | ||
<label style="display:flex;align-items: center;"> | ||
<input type="checkbox" checked={messageLoggerEnabled} style="margin: 0 5px;"/> | ||
Enable Message Logger | ||
</label> | ||
<label style="display:flex;align-items: center;"> | ||
<input type="checkbox" checked={verboseLogsEnabled} style="margin: 0 5px;"/> | ||
Enable Verbose Logs | ||
</label> | ||
<button style="margin-left: auto;border: none;margin-bottom: 0;background:var(--red)" onclick={()=>logsContainer.innerHTML=""}>Clear logs</button> | ||
<button style="border: none;margin-bottom: 0;" onclick={()=>logsContainer.scrollTo(0, logsContainer.scrollHeight)}>Scroll to bottom</button> | ||
</div> | ||
<b style="margin-bottom:20px;"> | ||
Backend Logs ({app.backend?.toString()}) | ||
</b> | ||
{logsContainer} | ||
</div>; | ||
|
||
effect(() => { | ||
if (messageLoggerEnabled.val) DebugLogs.enableMessageLogger.to(app.backend!)(); | ||
else DebugLogs.disableMessageLogger.to(app.backend!)(); | ||
}); | ||
|
||
effect(() => { | ||
if (verboseLogsEnabled.val) DebugLogs.enableVerboseLogs.to(app.backend!)(); | ||
else DebugLogs.disableVerboseLogs.to(app.backend!)(); | ||
}); | ||
|
||
|
||
(document as any).body.appendChild(component); | ||
(document as any).body.style.margin = "0"; | ||
|
||
const stream = await DebugLogs.getLogs.to(app.backend!)(); | ||
|
||
const reader = stream.getReader(); | ||
|
||
while (true) { | ||
const val = await reader.read(); | ||
const child = <span style="display:flex;gap:20px;"> | ||
<span style="color:var(--text-light);white-space: nowrap;">{new Date().toLocaleTimeString()}</span> | ||
<span>{unsafeHTML(convertANSIToHTML(val.value as string))}</span> | ||
</span>; | ||
const scrollDown = Math.abs(logsContainer.scrollHeight - logsContainer.scrollTop - logsContainer.clientHeight) < 1; | ||
logsContainer.appendChild(child); | ||
setTimeout(() => { | ||
if (scrollDown) { | ||
logsContainer.scrollTo(0, logsContainer.scrollHeight); | ||
} | ||
}, 10); | ||
if (val.done) break; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(document as any).body.append( | ||
<div style="padding: 15px;"> | ||
<h1>UIX Debugging Tools</h1> | ||
<ul> | ||
<li><a href="/@debug/logs">Backend Logs</a></li> | ||
<li><a href="/@debug/network">Network Status</a></li> | ||
</ul> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {communicationHub} from "datex-core-legacy/network/communication-hub.ts"; | ||
|
||
@endpoint export class DebugNetwork { | ||
@property static getComStatus() { | ||
return communicationHub.handler.getStatus() | ||
} | ||
|
||
@property static getEndpointSockets(endpoint: string) { | ||
return communicationHub.handler.getEndpointSockets(endpoint) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { DebugNetwork } from "./network-backend.ts"; | ||
import { convertANSIToHTML } from "../../utils/ansi-to-html.ts"; | ||
import { app } from "../app.ts"; | ||
|
||
const endpoint = $$("") | ||
|
||
const status = <div style="background: var(--accent-bg);border-radius: 10px;padding: 15px;"></div>; | ||
const endpointSockets = <div></div> | ||
const container = <div> | ||
{status} | ||
<div style="display:flex;gap:10px;margin:20px 0px;"> | ||
<input type="text" value={endpoint} style="width:500px"/> | ||
<input type="button" value="Get Endpoint Sockets" onclick={updateEndpointSockets}/> | ||
</div> | ||
{endpointSockets} | ||
</div> | ||
|
||
|
||
const getComStatus = DebugNetwork.getComStatus.to(app.backend!) | ||
const getEndpointSockets = DebugNetwork.getEndpointSockets.to(app.backend!) | ||
|
||
async function updateContent() { | ||
const content = await getComStatus(); | ||
status.innerHTML = convertANSIToHTML(content) | ||
} | ||
|
||
async function updateEndpointSockets() { | ||
const content = await getEndpointSockets(endpoint.val); | ||
endpointSockets.innerHTML = convertANSIToHTML(content) | ||
} | ||
|
||
|
||
updateContent(); | ||
setInterval(updateContent, 3000); | ||
|
||
(document as any).body.append(container); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters