-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathLogTable.js
More file actions
207 lines (191 loc) Β· 6.2 KB
/
LogTable.js
File metadata and controls
207 lines (191 loc) Β· 6.2 KB
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
import {Component} from 'react';
import {LogEntry} from './LogEntry.js';
import {LogLevel} from './LogLevel.js';
import MediaQuery from 'react-responsive';
import {convertDateFormat} from '../DateFormatConverter.js'
import {Settings} from './Settings';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
import {copyTextToClipboard} from '../Providers/ClipboardProvider';
import {ExceptionParser} from '../ExceptionParser';
const exceptionParser = new ExceptionParser();
import style from './LogTable.css';
export class LogTable extends Component {
state = {
showLevelSettings: false,
highlightedRequest: null,
copyActive: null
};
toggleLevelSettings = () => {
this.setState({showLevelSettings: !this.state.showLevelSettings});
};
toggleRelativeTime = () => {
this.props.setRelative(!this.props.relative);
};
highlightRequest (highlightedRequest) {
this.setState({highlightedRequest});
};
formatDate(entry, relative) {
const time = new Date(entry.time);
if (relative) {
return OC.Util.relativeModifiedDate(time);
} else {
return OC.Util.formatDate(time, convertDateFormat(this.props.dateFormat));
}
};
render () {
const timeClass = style.time + ((this.props.relative) ? (' ' + style.relative) : '');
let rows = this.props.entries.map((entry, i) => {
let className = style['level_' + entry.level];
if (entry.reqId === this.state.highlightedRequest) {
className += ' ' + style.highlight;
}
const copyEntry = (raw) => {
const text = (raw) ?
JSON.stringify(entry) :
`
[${entry.app}] ${LogLevel.levels[entry.level]}: ${exceptionParser.format(entry.message)}\n\n` +
((entry.method) ? `${entry.method} ${entry.url}\n` : '') +
((entry.remoteAddr) ? `from ${entry.remoteAddr} ` : '') +
((entry.user !== '--') ? `by ${entry.user} ` : '') +
`at ${entry.time}\n`;
copyTextToClipboard(text.trim());
this.setState({copyActive: null});
};
return (
<tr className={className + (this.state.copyActive === entry.id ? ' ' + style.active : '')}
key={entry.id}
onClick={this.highlightRequest.bind(this, entry.reqId)}>
<td className={style.level}><LogLevel level={entry.level}/>
</td>
<td className={style.app}>{entry.app}</td>
<td className={style.message}><LogEntry
message={entry.message}/></td>
<td className={style.copy}>
<button title={t('logreader', 'Copy')}
className="icon icon-clippy" onClick={() => {
this.setState({copyActive: this.state.copyActive === entry.id ? null : entry.id})
}}></button>
{
(this.state.copyActive === entry.id) ?
<div
className={style.copyMenu + ' popovermenu bubble open menu'}>
<ul>
<li>
<a className="menuitem icon icon-clippy"
onClick={() => copyEntry(true)}>
{t('logreader', 'Copy raw')}
</a>
</li>
<li>
<a className="menuitem icon icon-clippy"
onClick={() => copyEntry(false)}>
{t('logreader', 'Copy formatted')}
</a>
</li>
</ul>
</div> :
[]
}
</td>
<td className={timeClass}
title={this.formatDate(entry, !this.props.relative)}>{this.formatDate(entry, this.props.relative)}</td>
</tr>
)
});
const smallRows = this.props.entries.map((entry, i) => {
return (
<div className={style['level_' + entry.level] + ' ' + style.row}
key={i}>
<div className={style.level + ' ' + style.column}><LogLevel
level={entry.level}/>
</div>
<div
className={style.app + ' ' + style.column}>{entry.app}</div>
<div
className={timeClass + ' ' + style.column}>{this.formatDate(entry, this.props.relative)}</div>
<div className={style.message + ' ' + style.column}>
<LogEntry
message={entry.message}/></div>
</div>
)
});
if (rows.length === 0) {
rows = <tr className={style.empty}>
<td colSpan="4">
<div className="emptycontent">
<div className="icon-filetype-text"/>
<h2>{t('logreader', 'No server logs')}</h2>
<p>{(this.props.hidden > 0) ? t('logreader', 'One or more entries are hidden by the log level filter') : t('logreader', 'Everything is working fine')}</p>
</div>
</td>
</tr>
}
const levelSettingsHeader = (
<span onClick={this.toggleLevelSettings}>
Level
<span className={style['log-settings-toggle'] + ' icon-more'}/>
</span>
);
const levelHeader = this.props.inlineSettings ? (levelSettingsHeader) : t('logreader', 'Level');
return (
<div>
<MediaQuery minWidth={750}>
<table className={style.logs}>
<thead>
<tr>
<th className={style.level + ' ' + (this.state.showLevelSettings ? style.active : '')}>
{levelHeader}
{
this.state.showLevelSettings ?
<Settings
availableLogFiles={this.props.availableLogFiles}
setLevel={this.props.setLevel}
levels={this.props.levels}
live={this.props.live}
setLive={this.props.setLive}
live={this.props.live}
setLogFile={this.props.setLogFile}
logFile={this.props.logFile}
onCustomLogFile={this.props.onCustomLogFile}
/> :
<div className="hidden"/>
}
</th>
<th className={style.app}>{t('logreader', 'App')}</th>
<th className={style.message}>{t('logreader', 'Message')}</th>
<th className={style.copy}></th>
<th className={timeClass}
onClick={this.toggleRelativeTime}>{t('logreader', 'Time')}
</th>
</tr>
</thead>
<ReactCSSTransitionGroup
transitionName="highlight"
transitionEnterTimeout={1500}
transitionLeaveTimeout={1500}
component="tbody"
>
{rows}
</ReactCSSTransitionGroup>
</table>
</MediaQuery>
<MediaQuery maxWidth={768}>
<div className={style.smallHeader}>
{levelHeader}
{
this.state.showLevelSettings ?
<Settings
setLevel={this.props.setLevel}
levels={this.props.levels}
/> :
<div className="hidden"/>
}
</div>
<div className={style.logs}>
{smallRows}
</div>
</MediaQuery>
</div>
);
}
}