azurite
Version:
An open source Azure Storage API compatible server
39 lines • 1.46 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const winston_1 = require("winston");
const ILoggerStrategy_1 = require("./ILoggerStrategy");
/**
* A logger strategy can log to console or file.
*
* @export
* @class WinstonLoggerStrategy
* @implements {ILoggerStrategy}
*/
class WinstonLoggerStrategy {
/**
* Creates an instance of WinstonLoggerStrategy.
*
* @param {LogLevels} [level=LogLevels.Debug]
* @param {string} [logfile] Log to specific file, otherwise to console.
* @memberof WinstonLoggerStrategy
*/
constructor(level = ILoggerStrategy_1.LogLevels.Debug, logfile) {
this.winstonLogger = (0, winston_1.createLogger)({
format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.printf(info => `${info.timestamp} ${info.contextID} ${info.level}: ${info.message}`)),
level
});
if (logfile) {
this.fileTransport = new winston_1.transports.File({ filename: logfile });
this.winstonLogger.add(this.fileTransport);
}
else {
this.consoleTransport = new winston_1.transports.Console();
this.winstonLogger.add(this.consoleTransport);
}
}
log(level, message, contextID = "\t") {
this.winstonLogger.log({ level, message, contextID });
}
}
exports.default = WinstonLoggerStrategy;
//# sourceMappingURL=WinstonLoggerStrategy.js.map
;