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

Commit

Permalink
Proper order for status logs (#3055) (#3062)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac authored and jacogr committed Nov 1, 2016
1 parent a02a8d3 commit 9e7313a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
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 });
}
}

0 comments on commit 9e7313a

Please sign in to comment.