// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import LoadingScreen from 'components/loading_screen.jsx'; import React from 'react'; import PropTypes from 'prop-types'; import {FormattedMessage} from 'react-intl'; export default class Logs extends React.PureComponent { static propTypes = { /* * Array of logs to render */ logs: PropTypes.arrayOf(PropTypes.string).isRequired, actions: PropTypes.shape({ /* * Function to fetch logs */ getLogs: PropTypes.func.isRequired }).isRequired } constructor(props) { super(props); this.state = { loadingLogs: true }; } componentDidMount() { this.refs.logPanel.focus(); this.props.actions.getLogs().then( () => this.setState({loadingLogs: false}) ); } componentDidUpdate() { // Scroll Down to get the latest logs var node = this.refs.logPanel; node.scrollTop = node.scrollHeight; node.focus(); } reload = () => { this.setState({loadingLogs: true}); this.props.actions.getLogs().then( () => this.setState({loadingLogs: false}) ); } render() { let content = null; if (this.state.loadingLogs) { content = ; } else { content = []; for (let i = 0; i < this.props.logs.length; i++) { const style = { whiteSpace: 'nowrap', fontFamily: 'monospace' }; if (this.props.logs[i].indexOf('[EROR]') > 0) { style.color = 'red'; } content.push(
); content.push( {this.props.logs[i]} ); } } return (

{content}
); } }