Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix status log order #3062

Merged
merged 1 commit into from
Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions js/src/views/Status/components/Debug/Debug.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,26 @@
.logs {
margin: 0;
max-width: 100%;
}

.log {
font-family: monospace;
white-space: pre-line;
word-wrap: break-word;
color: #aaa;
margin: 0.5em 0;
display: flex;
align-items: center;
}

.logDate {
color: green;
font-size: 0.85em;
margin-right: 0.5em;
}

.logText {
flex: 1;
}

.stopped {
Expand Down
44 changes: 41 additions & 3 deletions js/src/views/Status/components/Debug/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import React, { Component, PropTypes } from 'react';
import AvPause from 'material-ui/svg-icons/av/pause';
import AvPlay from 'material-ui/svg-icons/av/play-arrow';
import AvReplay from 'material-ui/svg-icons/av/replay';
import ReorderIcon from 'material-ui/svg-icons/action/reorder';

import { Container, ContainerTitle } from '../../../../ui';

Expand All @@ -32,6 +33,10 @@ export default class Debug extends Component {
nodeStatus: PropTypes.object.isRequired
}

state = {
reversed: true
}

render () {
const { nodeStatus } = this.props;
const { devLogsLevels } = nodeStatus;
Expand Down Expand Up @@ -66,16 +71,43 @@ export default class Debug extends Component {

renderLogs () {
const { nodeStatus } = this.props;
const { reversed } = this.state;
const { devLogs } = nodeStatus;

const dateRegex = /^(\d{4}.\d{2}.\d{2}.\d{2}.\d{2}.\d{2})(.*)$/i;

if (!devLogs) {
return null;
}

const logs = reversed
? [].concat(devLogs).reverse()
: [].concat(devLogs);

const text = logs
.map((log, index) => {
const logDate = dateRegex.exec(log);

if (!logDate) {
return (
<p key={ index } className={ styles.log }>
{ log }
</p>
);
}

return (
<p key={ index } className={ styles.log }>
<span className={ styles.logDate }>{ logDate[1] }</span>
<span className={ styles.logText }>{ logDate[2] }</span>
</p>
);
});

return (
<pre className={ styles.logs }>
{ devLogs.reverse().join('\n') }
</pre>
<div className={ styles.logs }>
{ text }
</div>
);
}

Expand All @@ -89,6 +121,7 @@ export default class Debug extends Component {
<div className={ styles.actions }>
<a onClick={ this.toggle }>{ toggleButton }</a>
<a onClick={ this.clear }><AvReplay /></a>
<a onClick={ this.reverse } title='Reverse Order'><ReorderIcon /></a>
</div>
);
}
Expand All @@ -105,4 +138,9 @@ export default class Debug extends Component {

toggleStatusLogs(!devLogsEnabled);
}

reverse = () => {
const { reversed } = this.state;
this.setState({ reversed: !reversed });
}
}