From c8bf6e748ab426ad89fba556da618a79647a6463 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 8 Oct 2021 09:41:23 -0500 Subject: connect hub and display logs --- src/web/src/components/System/Logs.js | 68 ++++++++++++++++++++++++++++---- src/web/src/components/System/System.css | 16 ++++++++ 2 files changed, 76 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Logs.js b/src/web/src/components/System/Logs.js index b98a557a..72026fd1 100644 --- a/src/web/src/components/System/Logs.js +++ b/src/web/src/components/System/Logs.js @@ -1,22 +1,74 @@ import React, { Component } from 'react'; -import { Segment, Tab } from 'semantic-ui-react'; +import { Table, Loader, Dimmer } from 'semantic-ui-react'; + +import { createLogsHubConnection } from '../../lib/hubFactory'; + import './System.css'; +const initialState = { + logs: [], + connected: false, +} + +const levels = { + 'Debug': 'DBG', + 'Warning': 'WRN', + 'Error': 'ERR', + 'Information': 'INF' +} + +const maxLogs = 500; + class Logs extends Component { + state = initialState; + componentDidMount = () => { - } + const logsHub = createLogsHubConnection(); + + logsHub.on('buffer', (buffer) => { + this.setState({ connected: true, logs: buffer.reverse().slice(0, maxLogs) }); + }) + + logsHub.on('log', (log) => { + this.setState({ connected: true, logs: [log].concat(this.state.logs).slice(0, maxLogs) }); + }) - componentWillUnmount = () => { + logsHub.onreconnecting(() => this.setState({ connected: false })); + logsHub.onclose(() => this.setState({ connected: false })); + logsHub.onreconnected(() => this.setState({ connected: true })); + logsHub.start(); + } + + formatTimestamp = (timestamp) => { + const date = new Date(timestamp); + return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`; } render = () => { + const { connected, logs } = this.state; + return ( -
- +
+ {!connected && foo} + {connected && + + + + Timestamp + Level + Message + + + + {logs.map((log, index) => + {this.formatTimestamp(log.timestamp)} + {levels[log.level] || log.level} + {log.message} + )} + +
+ }
); } diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css index a2720e39..a0068963 100644 --- a/src/web/src/components/System/System.css +++ b/src/web/src/components/System/System.css @@ -6,4 +6,20 @@ margin-right: auto !important; margin-top: 15px !important; margin-bottom: 17px; +} + +.logs-table { + font-size: smaller; +} + +.logs-table-body { + font-family: monospace; +} + +.logs-table-message { + word-break: break-all; +} + +.logs { + min-height: 100px; } \ No newline at end of file -- cgit v1.2.3