Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("../config");
const logger_1 = require("../logger");
const egg_logger_1 = require("egg-logger");
// 默认配置
let options = {
level: 'INFO',
dir: 'logs',
sizeLimit: 1024 * 1024 * 5,
file: true
};
const logConf = config_1.config.getItem('log');
// 融合配置
options = Object.assign({}, options, logConf);
exports.logger = new egg_logger_1.Logger({});
// 如果file开启,则打开,否则关闭
if (options.file) {
exports.logger.set('file',
// 日志输出到文件
new logger_1.FileTransport({
dir: options.dir,
sizeLimit: options.sizeLimit,
level: options.level
}));
}
exports.logger.set('console',
// 日志输出到终端
new logger_1.ConsoleTransport({
level: options.level
}));
/**
const Logger = require('egg-logger').Logger;
const { FileTransport } = require('../lin/logger/file');
const { ConsoleTransport } = require('../lin/logger/console');
const logger = new Logger();
logger.set(
'file',
new FileTransport({
dir: 'log',
sizeLimit: 1024 * 5,
level: 'DEBUG'
})
);
logger.set(
'console',
new ConsoleTransport({
level: 'DEBUG'
})
);
logger.debug('debug foo'); // only output to stdout
'use strict';
const { Logger, ConsoleTransport } = require('egg-logger');
const { consoleFormatter } = require('egg-logger/lib/utils');
const logger = new Logger();
logger.set('console', new ConsoleTransport({
level: 'INFO',
formatter: consoleFormatter,
}));
module.exports = logger;
constructor(options: ICoreSDKOptions) {
this.options = options;
this.coreContext = {
mode: options.mode,
appName: options.appName,
appDir: options.appDir,
processName: options.processName || options.mode,
config: {},
logger: new Logger({}),
};
debug('constructing CoreSDK %j', options);
if(this.options.extendContext) {
Object.assign(this.coreContext, this.options.extendContext);
}
this.loadConfig(defaultConfig, dirname(require.resolve('./pandoraConfig')));
}
'use strict';
const Logger = require('egg-logger').Logger;
const ConsoleTransport = require('egg-logger').ConsoleTransport;
const logger = new Logger();
logger.set('console', new ConsoleTransport({
level: 'DEBUG',
}));
module.exports = logger;