-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinstonLoggerAdapter.js
64 lines (55 loc) · 1.54 KB
/
WinstonLoggerAdapter.js
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
const LoggerAdapter = require('./LoggerAdapter');
import { logger, addTransport, configureLogger } from './WinstonLogger';
const MILLISECONDS_IN_A_DAY = 24 * 60 * 60 * 1000;
export class WinstonLoggerAdapter extends LoggerAdapter {
constructor(options) {
super();
if (options) {
configureLogger(options);
}
}
log() {
return logger.log.apply(logger, arguments);
}
addTransport(transport) {
// Note that this is calling addTransport
// from logger. See import - confusing.
// but this is not recursive.
addTransport(transport);
}
// custom query as winston is currently limited
query(options, callback = () => {}) {
if (!options) {
options = {};
}
// defaults to 7 days prior
const from =
options.from || new Date(Date.now() - 7 * MILLISECONDS_IN_A_DAY);
const until = options.until || new Date();
const limit = options.size || 10;
const order = options.order || 'desc';
const level = options.level || 'info';
const queryOptions = {
from,
until,
limit,
order,
};
return new Promise((resolve, reject) => {
logger.query(queryOptions, (err, res) => {
if (err) {
callback(err);
return reject(err);
}
if (level === 'error') {
callback(res['parse-server-error']);
resolve(res['parse-server-error']);
} else {
callback(res['parse-server']);
resolve(res['parse-server']);
}
});
});
}
}
export default WinstonLoggerAdapter;