Log4js-禁用HTTP调用的日志

时间:2019-06-19 13:11:55

标签: node.js log4js-node

我正在使用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]开发-:: 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,   例如Gecko)Chrome / 75.0.3770.90 Safari / 537.36“   [2019-06-19T16:02:16.182] [关闭]开发-:: 1--“选项   / 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,   例如Gecko)Chrome / 75.0.3770.90 Safari / 537.36“   [2019-06-19T16:02:16.189] [OFF]开发-:: 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,   例如Gecko)Chrome / 75.0.3770.90 Safari / 537.36“

2 个答案:

答案 0 :(得分:1)

在我的代码中,它与app.js中的以下行有关:

const logger = require('morgan');
app.use(logger('dev'));

我删除了这些行,以便仅使用log4js,而不是Morgan。

答案 1 :(得分:0)

删除app.js中的行即可解决。谢谢。