diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-10-08 10:02:51 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-08 10:02:51 -0500 |
| commit | 28ec4cd64046deb7bd37ff5c02e32b76d79edf20 (patch) | |
| tree | 3739f65bf88bd0f6c3c151cceef2d8f0bdf00c81 /src/web | |
| parent | 2a26742088bd5951dcd545582d44ac5a8b381d5d (diff) | |
| parent | 30a9c7f8a0fbd921930a2b2f712162f4fc58c8b3 (diff) | |
| download | slskd-28ec4cd64046deb7bd37ff5c02e32b76d79edf20.tar.gz | |
Merge pull request #212 from slskd/logs
Logs
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/App.js | 7 | ||||
| -rw-r--r-- | src/web/src/components/System/Info.js | 13 | ||||
| -rw-r--r-- | src/web/src/components/System/Logs.js | 77 | ||||
| -rw-r--r-- | src/web/src/components/System/System.css | 25 | ||||
| -rw-r--r-- | src/web/src/components/System/System.js | 29 | ||||
| -rw-r--r-- | src/web/src/lib/hubFactory.js | 6 |
6 files changed, 155 insertions, 2 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index d9c7cbb6..f8813820 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -12,6 +12,7 @@ import Browse from './Browse/Browse'; import Users from './Users/Users'; import Transfers from './Transfers/Transfers'; import Chat from './Chat/Chat'; +import System from './System/System'; import LoginForm from './LoginForm'; import { @@ -198,6 +199,11 @@ class App extends Component { href="https://github.com/slskd/slskd/releases">See Release Notes</Button> </Modal.Actions> </Modal>} + <Link to='system'> + <Menu.Item> + <Icon name='cogs'/>System + </Menu.Item> + </Link> {session.isLoggedIn() && <Modal trigger={ <Menu.Item> @@ -220,6 +226,7 @@ class App extends Component { <Route path='*/rooms' render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/> <Route path='*/uploads' render={(props) => this.withTokenCheck(<Transfers {...props} direction='upload'/>)}/> <Route path='*/downloads' render={(props) => this.withTokenCheck(<Transfers {...props} direction='download'/>)}/> + <Route path='*/system' render={(props) => this.withTokenCheck(<System state={this.state.applicationState}/>)}/> <Route path='*/' render={(props) => this.withTokenCheck(<Search {...props}/>)}/> </Switch> </Sidebar.Pusher> diff --git a/src/web/src/components/System/Info.js b/src/web/src/components/System/Info.js new file mode 100644 index 00000000..ee132aec --- /dev/null +++ b/src/web/src/components/System/Info.js @@ -0,0 +1,13 @@ +import React, { Component } from 'react'; + +class Info extends Component { + render = () => { + return ( + <div> + <pre>{JSON.stringify(this.props.state, null, 2)}</pre> + </div> + ); + } +} + +export default Info;
\ No newline at end of file diff --git a/src/web/src/components/System/Logs.js b/src/web/src/components/System/Logs.js new file mode 100644 index 00000000..aa545c63 --- /dev/null +++ b/src/web/src/components/System/Logs.js @@ -0,0 +1,77 @@ +import React, { Component } from '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) }); + }) + + 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 className='logs'> + {!connected && <Dimmer active inverted><Loader inverted/></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> + ); + } +} + +export default Logs;
\ No newline at end of file diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css new file mode 100644 index 00000000..a0068963 --- /dev/null +++ b/src/web/src/components/System/System.css @@ -0,0 +1,25 @@ +.system { + padding-left: 15px; + padding-right: 15px; + max-width: 1200px !important; + margin-left: auto !important; + 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 diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js new file mode 100644 index 00000000..e1e61c5c --- /dev/null +++ b/src/web/src/components/System/System.js @@ -0,0 +1,29 @@ +import React, { Component } from 'react'; +import { Segment, Tab } from 'semantic-ui-react'; +import './System.css'; +import Info from './Info'; +import Logs from './Logs'; + +class System extends Component { + componentDidMount = () => { + } + + componentWillUnmount = () => { + + } + + render = () => { + return ( + <div className='system'> + <Segment raised> + <Tab panes={[ + { menuItem: 'Info', render: () => <Tab.Pane><Info state={this.props.state}/></Tab.Pane> }, + { menuItem: 'Logs', render: () => <Tab.Pane><Logs/></Tab.Pane> }, + ]}/> + </Segment> + </div> + ); + } +} + +export default System;
\ No newline at end of file diff --git a/src/web/src/lib/hubFactory.js b/src/web/src/lib/hubFactory.js index 0fead578..3281a80c 100644 --- a/src/web/src/lib/hubFactory.js +++ b/src/web/src/lib/hubFactory.js @@ -14,7 +14,9 @@ export const createHubConnection = ({ url }) => }) .withAutomaticReconnect() .withHubProtocol(new JsonHubProtocol()) - .configureLogging(LogLevel.Information) + .configureLogging(LogLevel.Warning) .build(); -export const createApplicationHubConnection = () => createHubConnection({ url: `${rootUrl}/hub/application` });
\ No newline at end of file +export const createApplicationHubConnection = () => createHubConnection({ url: `${rootUrl}/hub/application` }); + +export const createLogsHubConnection = () => createHubConnection({ url: `${rootUrl}/hub/logs` });
\ No newline at end of file |
