mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
09.43.2018 1a21e0d3baca3870611a1fe712027a559d9a4b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React from 'react';
import {getRestServiceUrl} from '../../../utilities/global';
import LogTable from './LogTable';
import './LogViewer.css';
import PropTypes from 'prop-types';
 
class LogEmbeddedPanel extends React.Component {
 
    componentDidMount = () => {
        this.reload();
    };
 
    handleToggleSortOrder = () => {
        this.setState({
            ascendingOrder: (this.state.ascendingOrder === 'true') ? 'false' : 'true'
        }, () => {
            this.reload()
        });
    };
 
    handleInputChange = (event) => {
        this.props.changeFilter(event.target.name, event.target.value);
    };
 
    reload = () => {
        this.setState({
            isFetching: true,
            failed: false,
            logEntries: undefined
        });
        fetch(getRestServiceUrl("logging/query", {
            search: this.state.search,
            treshold: this.props.treshold,
            maxSize: this.props.maxSize,
            ascendingOrder: this.state.ascendingOrder,
            mdcTemplatePk: this.props.mdcTemplatePk,
            mdcTemplateDefinitionPk: this.props.mdcTemplateDefinitionPk
        }), {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            }
        })
            .then(response => response.json())
            .then(json => {
                const logEntries = json.map(logEntry => {
                    return {
                        level: logEntry.level.toLowerCase(),
                        message: logEntry.message,
                        logDate: logEntry.logDate,
                        javaClass: logEntry.javaClass,
                        javaClassSimpleName: logEntry.javaClassSimpleName,
                        lineNumber: logEntry.lineNumber,
                        methodName: logEntry.methodName
                    };
                });
                this.setState({
                    isFetching: false,
                    logEntries
                })
            })
            .catch(() => this.setState({isFetching: false, failed: true}));
    };
 
 
    render = () => {
        return <LogTable
            search={''}
            locationFormat={this.props.locationFormat}
            entries={this.state.logEntries}
            ascendingOrder={this.state.ascendingOrder}
            toggleOrder={this.handleToggleSortOrder}
            showStackTrace={this.props.showStackTrace}
        />
    };
 
    constructor(props) {
        super(props);
        this.state = {
            search: '',
            ascendingOrder: 'false'
        }
    }
}
 
LogEmbeddedPanel.propTypes = {
    locationFormat: PropTypes.oneOf(['none', 'short', 'normal']),
    showStackTrace: PropTypes.oneOf(['true', 'false']),
    threshold: PropTypes.oneOf(['error', 'warn', 'info', 'debug', 'trace']),
    maxSize: PropTypes.oneOf(['50', '100', '500', '1000', '10000']),
    mdcTemplatePk: PropTypes.string,
    mdcTemplateDefinitionPk: PropTypes.string,
    search: PropTypes.string
};
 
LogEmbeddedPanel.defaultProps = {
    locationFormat: 'none',
    showStackTrace: 'false',
    treshold: 'info',
    maxSize: '50',
    mdcTemplatePk: null,
    mdcTemplateDefinitionPk: null,
    search: ''
};
 
export default LogEmbeddedPanel;