logger.js
916 Bytes
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
'use strict';
/**
* Sequelize module for debug and deprecation messages.
* It require a `context` for which messages will be printed.
*
* @module logging
* @private
*/
const depd = require('depd'),
debug = require('debug'),
_ = require('lodash');
class Logger {
constructor(config) {
this.config = _.extend({
context: 'sequelize',
debug: true
}, config || {});
this.depd = depd(this.config.context);
this.debug = debug(this.config.context);
}
deprecate(message) {
this.depd(message);
}
debug(message) {
this.config.debug && this.debug(message);
}
warn(message) {
console.warn(`(${this.config.context}) Warning: ${message}`);
}
debugContext(childContext) {
if (!childContext) {
throw new Error('No context supplied to debug');
}
return debug([this.config.context, childContext].join(':'));
}
}
module.exports = Logger;