mirror of
https://github.com/eggjs/egg.git
synced 2024-12-04 07:14:30 +00:00
feat: don’t force logger to use INFO level in prod (#1218)
This commit is contained in:
parent
95fbd47f4c
commit
5a9531abbe
@ -226,6 +226,7 @@ module.exports = appInfo => {
|
||||
agentLogName: 'egg-agent.log',
|
||||
errorLogName: 'common-error.log',
|
||||
coreLogger: {},
|
||||
allowDebugAtProd: true,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -6,7 +6,7 @@ module.exports = function createLoggers(app) {
|
||||
const loggerConfig = app.config.logger;
|
||||
loggerConfig.type = app.type;
|
||||
|
||||
if (app.config.env === 'prod' && loggerConfig.level === 'DEBUG') {
|
||||
if (app.config.env === 'prod' && loggerConfig.level === 'DEBUG' && loggerConfig.allowDebugAtProd === true) {
|
||||
loggerConfig.level = 'INFO';
|
||||
}
|
||||
|
||||
|
||||
13
test/fixtures/apps/mock-production-app-do-not-force/config/config.js
vendored
Normal file
13
test/fixtures/apps/mock-production-app-do-not-force/config/config.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
exports.watcher = {
|
||||
// watcher 在 prod 中默认没有设置 type,防止框架开发者忘记设置,这里设置一下,避免报错
|
||||
type: 'development',
|
||||
};
|
||||
|
||||
exports.logger = {
|
||||
level: 'DEBUG',
|
||||
allowDebugAtProd: false,
|
||||
};
|
||||
|
||||
exports.keys = 'foo';
|
||||
5
test/fixtures/apps/mock-production-app-do-not-force/config/config.unittest.js
vendored
Normal file
5
test/fixtures/apps/mock-production-app-do-not-force/config/config.unittest.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
exports.logger = {
|
||||
consoleLevel: 'NONE',
|
||||
};
|
||||
3
test/fixtures/apps/mock-production-app-do-not-force/config/map.json
vendored
Normal file
3
test/fixtures/apps/mock-production-app-do-not-force/config/map.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
3
test/fixtures/apps/mock-production-app-do-not-force/package.json
vendored
Normal file
3
test/fixtures/apps/mock-production-app-do-not-force/package.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "mock-production-app-do-not-force"
|
||||
}
|
||||
@ -29,6 +29,21 @@ describe('test/lib/core/logger.test.js', () => {
|
||||
assert(app.config.logger.disableConsoleAfterReady === true);
|
||||
});
|
||||
|
||||
it('should got right level on prod env when set allowDebugAtProd to false', function* () {
|
||||
mm.env('prod');
|
||||
mm(process.env, 'EGG_LOG', '');
|
||||
mm(process.env, 'HOME', utils.getFilepath('apps/mock-production-app-do-not-force/config'));
|
||||
app = utils.app('apps/mock-production-app-do-not-force');
|
||||
yield app.ready();
|
||||
|
||||
assert(app.config.logger.allowDebugAtProd === false);
|
||||
|
||||
assert(app.logger.get('file').options.level === Logger.DEBUG);
|
||||
assert(app.logger.get('console').options.level === Logger.INFO);
|
||||
assert(app.coreLogger.get('file').options.level === Logger.DEBUG);
|
||||
assert(app.coreLogger.get('console').options.level === Logger.INFO);
|
||||
});
|
||||
|
||||
it('should got right level on local env', function* () {
|
||||
mm.env('local');
|
||||
mm(process.env, 'EGG_LOG', '');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user