// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import AdminStore from 'stores/admin_store.jsx'; import LoadingScreen from '../loading_screen.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import {FormattedMessage} from 'react-intl'; import React from 'react'; export default class Logs extends React.Component { constructor(props) { super(props); this.onLogListenerChange = this.onLogListenerChange.bind(this); this.reload = this.reload.bind(this); this.state = { logs: AdminStore.getLogs() }; } componentDidMount() { AdminStore.addLogChangeListener(this.onLogListenerChange); AsyncClient.getLogs(); this.refs.logPanel.focus(); } componentDidUpdate() { // Scroll Down to get the latest logs var node = this.refs.logPanel; node.scrollTop = node.scrollHeight; node.focus(); } componentWillUnmount() { AdminStore.removeLogChangeListener(this.onLogListenerChange); } onLogListenerChange() { this.setState({ logs: AdminStore.getLogs() }); } reload() { AdminStore.saveLogs(null); this.setState({ logs: null }); AsyncClient.getLogs(); } render() { var content = null; if (this.state.logs === null) { content = ; } else { content = []; for (var i = 0; i < this.state.logs.length; i++) { var style = { whiteSpace: 'nowrap', fontFamily: 'monospace' }; if (this.state.logs[i].indexOf('[EROR]') > 0) { style.color = 'red'; } content.push(
); content.push( {this.state.logs[i]} ); } } return (

{content}
); } }