summaryrefslogtreecommitdiffstats
path: root/webapp/components/admin_console/log_settings.jsx
blob: e18cb8a234a9c4938ac2ee37fd3bdff0cfd1f104 (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import * as Utils from 'utils/utils.jsx';

import AdminSettings from './admin_settings.jsx';
import BooleanSetting from './boolean_setting.jsx';
import DropdownSetting from './dropdown_setting.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import SettingsGroup from './settings_group.jsx';
import TextSetting from './text_setting.jsx';

export default class LogSettings extends AdminSettings {
    constructor(props) {
        super(props);

        this.getConfigFromState = this.getConfigFromState.bind(this);

        this.renderSettings = this.renderSettings.bind(this);
    }

    getConfigFromState(config) {
        config.LogSettings.EnableConsole = this.state.enableConsole;
        config.LogSettings.ConsoleLevel = this.state.consoleLevel;
        config.LogSettings.EnableFile = this.state.enableFile;
        config.LogSettings.FileLevel = this.state.fileLevel;
        config.LogSettings.FileLocation = this.state.fileLocation;
        config.LogSettings.FileFormat = this.state.fileFormat;
        config.LogSettings.EnableWebhookDebugging = this.state.enableWebhookDebugging;
        config.LogSettings.EnableDiagnostics = this.state.enableDiagnostics;

        return config;
    }

    getStateFromConfig(config) {
        return {
            enableConsole: config.LogSettings.EnableConsole,
            consoleLevel: config.LogSettings.ConsoleLevel,
            enableFile: config.LogSettings.EnableFile,
            fileLevel: config.LogSettings.FileLevel,
            fileLocation: config.LogSettings.FileLocation,
            fileFormat: config.LogSettings.FileFormat,
            enableWebhookDebugging: config.LogSettings.EnableWebhookDebugging,
            enableDiagnostics: config.LogSettings.EnableDiagnostics
        };
    }

    renderTitle() {
        return (
            <FormattedMessage
                id='admin.general.log'
                defaultMessage='Logging'
            />
        );
    }

    renderSettings() {
        const logLevels = [
            {value: 'DEBUG', text: 'DEBUG'},
            {value: 'INFO', text: 'INFO'},
            {value: 'ERROR', text: 'ERROR'}
        ];

        return (
            <SettingsGroup>
                <BooleanSetting
                    id='enableConsole'
                    label={
                        <FormattedMessage
                            id='admin.log.consoleTitle'
                            defaultMessage='Output logs to console: '
                        />
                    }
                    helpText={
                        <FormattedMessage
                            id='admin.log.consoleDescription'
                            defaultMessage='Typically set to false in production. Developers may set this field to true to output log messages to console based on the console level option.  If true, server writes messages to the standard output stream (stdout).'
                        />
                    }
                    value={this.state.enableConsole}
                    onChange={this.handleChange}
                />
                <DropdownSetting
                    id='consoleLevel'
                    values={logLevels}
                    label={
                        <FormattedMessage
                            id='admin.log.levelTitle'
                            defaultMessage='Console Log Level:'
                        />
                    }
                    value={this.state.consoleLevel}
                    onChange={this.handleChange}
                    disabled={!this.state.enableConsole}
                    helpText={
                        <FormattedMessage
                            id='admin.log.levelDescription'
                            defaultMessage='This setting determines the level of detail at which log events are written to the console. ERROR: Outputs only error messages. INFO: Outputs error messages and information around startup and initialization. DEBUG: Prints high detail for developers working on debugging issues.'
                        />
                    }
                />
                <BooleanSetting
                    id='enableFile'
                    label={
                        <FormattedMessage
                            id='admin.log.fileTitle'
                            defaultMessage='Output logs to file: '
                        />
                    }
                    helpText={
                        <FormattedMessage
                            id='admin.log.fileDescription'
                            defaultMessage='Typically set to true in production. When true, logged events are written to the mattermost.log file in the directory specified in the File Log Directory field. The logs are rotated at 10,000 lines and archived to a file in the same directory, and given a name with a datestamp and serial number. For example, mattermost.2017-03-31.001.'
                        />
                    }
                    value={this.state.enableFile}
                    onChange={this.handleChange}
                />
                <DropdownSetting
                    id='fileLevel'
                    values={logLevels}
                    label={
                        <FormattedMessage
                            id='admin.log.fileLevelTitle'
                            defaultMessage='File Log Level:'
                        />
                    }
                    value={this.state.fileLevel}
                    onChange={this.handleChange}
                    disabled={!this.state.enableFile}
                    helpText={
                        <FormattedMessage
                            id='admin.log.fileLevelDescription'
                            defaultMessage='This setting determines the level of detail at which log events are written to the log file. ERROR: Outputs only error messages. INFO: Outputs error messages and information around startup and initialization. DEBUG: Prints high detail for developers working on debugging issues.'
                        />
                    }
                />
                <TextSetting
                    id='fileLocation'
                    label={
                        <FormattedMessage
                            id='admin.log.locationTitle'
                            defaultMessage='File Log Directory:'
                        />
                    }
                    placeholder={Utils.localizeMessage('admin.log.locationPlaceholder', 'Enter your file location')}
                    helpText={
                        <FormattedMessage
                            id='admin.log.locationDescription'
                            defaultMessage='The location of the log files. If blank, they are stored in the ./logs directory. The path that you set must exist and Mattermost must have write permissions in it.'
                        />
                    }
                    value={this.state.fileLocation}
                    onChange={this.handleChange}
                    disabled={!this.state.enableFile}
                />
                <TextSetting
                    id='fileFormat'
                    label={
                        <FormattedMessage
                            id='admin.log.formatTitle'
                            defaultMessage='File Log Format:'
                        />
                    }
                    placeholder={Utils.localizeMessage('admin.log.formatPlaceholder', 'Enter your file format')}
                    helpText={this.renderFileFormatHelpText()}
                    value={this.state.fileFormat}
                    onChange={this.handleChange}
                    disabled={!this.state.enableFile}
                />
                <BooleanSetting
                    id='enableWebhookDebugging'
                    label={
                        <FormattedMessage
                            id='admin.log.enableWebhookDebugging'
                            defaultMessage='Enable Webhook Debugging:'
                        />
                    }
                    helpText={
                        <FormattedMessage
                            id='admin.log.enableWebhookDebuggingDescription'
                            defaultMessage='You can set this to false to disable the debug logging of all incoming webhook request bodies.'
                        />
                    }
                    value={this.state.enableWebhookDebugging}
                    onChange={this.handleChange}
                />
                <BooleanSetting
                    id='enableDiagnostics'
                    label={
                        <FormattedMessage
                            id='admin.log.enableDiagnostics'
                            defaultMessage='Enable Diagnostics and Error Reporting:'
                        />
                    }
                    helpText={
                        <FormattedHTMLMessage
                            id='admin.log.enableDiagnosticsDescription'
                            defaultMessage='Enable this feature to improve the quality and performance of Mattermost by sending error reporting and diagnostic information to Mattermost, Inc. Read our <a href="https://about.mattermost.com/default-privacy-policy/" target="_blank">privacy policy</a> to learn more.'
                        />
                    }
                    value={this.state.enableDiagnostics}
                    onChange={this.handleChange}
                />
            </SettingsGroup>
        );
    }

    renderFileFormatHelpText() {
        return (
            <div>
                <FormattedMessage
                    id='admin.log.formatDescription'
                    defaultMessage='Format of log message output. If blank will be set to "[%D %T] [%L] %M", where:'
                />
                <table
                    className='table table-bordered'
                    cellPadding='5'
                >
                    <tbody>
                        <tr>
                            <td>{'%T'}</td>
                            <td>
                                <FormattedMessage
                                    id='admin.log.formatTime'
                                    defaultMessage='Time (15:04:05 MST)'
                                />
                            </td>
                        </tr>
                        <tr>
                            <td>{'%D'}</td>
                            <td>
                                <FormattedMessage
                                    id='admin.log.formatDateLong'
                                    defaultMessage='Date (2006/01/02)'
                                />
                            </td>
                        </tr>
                        <tr>
                            <td>{'%d'}</td>
                            <td>
                                <FormattedMessage
                                    id='admin.log.formatDateShort'
                                    defaultMessage='Date (01/02/06)'
                                />
                            </td>
                        </tr>
                        <tr>
                            <td>{'%L'}</td>
                            <td>
                                <FormattedMessage
                                    id='admin.log.formatLevel'
                                    defaultMessage='Level (DEBG, INFO, EROR)'
                                />
                            </td>
                        </tr>
                        <tr>
                            <td>{'%S'}</td>
                            <td>
                                <FormattedMessage
                                    id='admin.log.formatSource'
                                    defaultMessage='Source'
                                />
                            </td>
                        </tr>
                        <tr>
                            <td>{'%M'}</td>
                            <td>
                                <FormattedMessage
                                    id='admin.log.formatMessage'
                                    defaultMessage='Message'
                                />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        );
    }
}