CartoDB-SQL-API/app/services/logger.js

56 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-05-23 23:24:48 +08:00
'use strict';
const bunyan = require('bunyan');
2018-06-08 16:59:34 +08:00
class Logger {
2018-05-23 23:24:48 +08:00
constructor (path, name) {
const env = process.env.NODE_ENV;
const logLevel = process.env.LOG_LEVEL;
2018-05-23 23:24:48 +08:00
const stream = {
level: logLevel ? logLevel : (env === 'test') ? 'fatal' : (env === 'development') ? 'debug' : 'info'
2018-05-23 23:24:48 +08:00
};
if (path) {
stream.path = path;
} else {
stream.stream = process.stdout;
}
this.path = path;
this.logger = bunyan.createLogger({
name,
streams: [stream]
});
}
fatal (...args) {
this.logger.fatal(...args);
2018-05-23 23:24:48 +08:00
}
error (...args) {
this.logger.error(...args);
}
warn (...args) {
this.logger.warn(...args);
}
info (...args) {
this.logger.info(...args);
}
debug (...args) {
this.logger.debug(...args);
}
trace (...args) {
this.logger.trace(...args);
2018-05-23 23:24:48 +08:00
}
2018-06-19 00:47:12 +08:00
reopenFileStreams () {
this.logger.reopenFileStreams();
}
2018-05-23 23:24:48 +08:00
}
2018-06-08 16:59:34 +08:00
module.exports = Logger;