Log4js - 禁用 http 调用的日志
Log4js - Disable logs for http calls
我正在使用 log4js 来记录消息。出于某种原因,记录器会自动记录 http 调用,但我找不到禁用它的方法。这是我的代码:
// Initialize the log4js logger by configurations parameters and appenders.
log4js.configure({
appenders: {
app: {
type: 'file',
filename: 'logs/app.log',
pattern: '-yyyy-MM-dd',
maxLogSize: LOGS_FILES_MAXIMUM_SIZE
},
mq: {
type: '@log4js-node/rabbitmq',
host: LOG_SERVER_HOST_ADDRESS,
port: LOG_SERVER_HOST_PORT,
username: LOG_SERVER_USERNAME,
password: LOG_SERVER_PASSWORD,
routing_key: LOG_SERVER_ROUTING_KEY,
exchange: LOG_SERVER_EXCHANGE_NAME,
mq_type: 'direct',
durable: true
}
},
categories: {
default: { appenders: ['app'], level: LogLevel.ALL },
development: { appenders: ['app'], level: LogLevel.ALL },
production: { appenders: ['app', 'mq'], level: LogLevel.ALL }
}
});
this.log = log4js.getLogger('production');
并在 app.js
this.app.use(log4js.connectLogger(log4js.getLogger('production'), { level: 'off' }));
出于某种原因,记录器会自动记录如下消息:
[2019-06-19T16:02:16.182] [OFF] development - ::1 - - "POST
/api/log/logMessage HTTP/1.1" 200 2
"http://localhost:3000/?recording-session-id=b983cb82-4812-4c43-87b3-a17e7ed1f6b4&environment=data-center"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/75.0.3770.90 Safari/537.36"
[2019-06-19T16:02:16.182] [OFF] development - ::1 - - "OPTIONS
/api/stream/getStreamData HTTP/1.1" 204 0
"http://localhost:3000/?recording-session-id=b983cb82-4812-4c43-87b3-a17e7ed1f6b4&environment=data-center"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/75.0.3770.90 Safari/537.36"
[2019-06-19T16:02:16.189] [OFF] development - ::1 - - "POST
/api/stream/getStreamData HTTP/1.1" 200 999
"http://localhost:3000/?recording-session-id=b983cb82-4812-4c43-87b3-a17e7ed1f6b4&environment=data-center"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/75.0.3770.90 Safari/537.36"
在我的代码中,它与 app.js 中的以下几行有关:
const logger = require('morgan');
app.use(logger('dev'));
我删除了这些行以便只使用 log4js,而不是 Morgan。
我正在使用 log4js 来记录消息。出于某种原因,记录器会自动记录 http 调用,但我找不到禁用它的方法。这是我的代码:
// Initialize the log4js logger by configurations parameters and appenders.
log4js.configure({
appenders: {
app: {
type: 'file',
filename: 'logs/app.log',
pattern: '-yyyy-MM-dd',
maxLogSize: LOGS_FILES_MAXIMUM_SIZE
},
mq: {
type: '@log4js-node/rabbitmq',
host: LOG_SERVER_HOST_ADDRESS,
port: LOG_SERVER_HOST_PORT,
username: LOG_SERVER_USERNAME,
password: LOG_SERVER_PASSWORD,
routing_key: LOG_SERVER_ROUTING_KEY,
exchange: LOG_SERVER_EXCHANGE_NAME,
mq_type: 'direct',
durable: true
}
},
categories: {
default: { appenders: ['app'], level: LogLevel.ALL },
development: { appenders: ['app'], level: LogLevel.ALL },
production: { appenders: ['app', 'mq'], level: LogLevel.ALL }
}
});
this.log = log4js.getLogger('production');
并在 app.js
this.app.use(log4js.connectLogger(log4js.getLogger('production'), { level: 'off' }));
出于某种原因,记录器会自动记录如下消息:
[2019-06-19T16:02:16.182] [OFF] development - ::1 - - "POST /api/log/logMessage HTTP/1.1" 200 2 "http://localhost:3000/?recording-session-id=b983cb82-4812-4c43-87b3-a17e7ed1f6b4&environment=data-center" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36" [2019-06-19T16:02:16.182] [OFF] development - ::1 - - "OPTIONS /api/stream/getStreamData HTTP/1.1" 204 0 "http://localhost:3000/?recording-session-id=b983cb82-4812-4c43-87b3-a17e7ed1f6b4&environment=data-center" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36" [2019-06-19T16:02:16.189] [OFF] development - ::1 - - "POST /api/stream/getStreamData HTTP/1.1" 200 999 "http://localhost:3000/?recording-session-id=b983cb82-4812-4c43-87b3-a17e7ed1f6b4&environment=data-center" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36"
在我的代码中,它与 app.js 中的以下几行有关:
const logger = require('morgan');
app.use(logger('dev'));
我删除了这些行以便只使用 log4js,而不是 Morgan。