aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-10-08 09:41:23 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-10-08 09:41:23 -0500
commitc8bf6e748ab426ad89fba556da618a79647a6463 (patch)
tree45a0bffedbfde11748b293acd53de22437e40fbb /src
parent736dfff36d7f533a69df838eb1594e71cac178b7 (diff)
downloadslskd-c8bf6e748ab426ad89fba556da618a79647a6463.tar.gz
connect hub and display logs
Diffstat (limited to 'src')
-rw-r--r--src/web/src/components/System/Logs.js68
-rw-r--r--src/web/src/components/System/System.css16
2 files changed, 76 insertions, 8 deletions
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 (
- <div>
- <ul>
- <li>log 1 here</li>
- <li>log 2 here</li>
- </ul>
+ <div className='logs'>
+ {!connected && <Dimmer active inverted><Loader inverted/>foo</Dimmer>}
+ {connected &&
+ <Table compact='very' className='logs-table'>
+ <Table.Header>
+ <Table.Row>
+ <Table.HeaderCell>Timestamp</Table.HeaderCell>
+ <Table.HeaderCell>Level</Table.HeaderCell>
+ <Table.HeaderCell>Message</Table.HeaderCell>
+ </Table.Row>
+ </Table.Header>
+ <Table.Body className='logs-table-body'>
+ {logs.map((log, index) => <Table.Row key={index} disabled={log.level === 'Debug'} warning={log.level === 'Warning'} negative={log.level === 'Error'}>
+ <Table.Cell>{this.formatTimestamp(log.timestamp)}</Table.Cell>
+ <Table.Cell>{levels[log.level] || log.level}</Table.Cell>
+ <Table.Cell className='logs-table-message'>{log.message}</Table.Cell>
+ </Table.Row>)}
+ </Table.Body>
+ </Table>
+ }
</div>
);
}
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