You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
916 B
47 lines
916 B
'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;
|
|
|