【问题标题】:good module is not working as expected好的模块没有按预期工作
【发布时间】:2018-05-25 17:16:20
【问题描述】:

我已经在 hapi 服务器中注册了好插件,并且我的所有回复都已登录。但是当我执行 console.logconsole.errorconsole.warnconsole.info 时,所有日志都以纯文本形式打印但不是很好的插件方式。

谁能帮我解决我可能错过的问题。

我已阅读以下文档:

【问题讨论】:

    标签: javascript hapijs hapi.js


    【解决方案1】:

    console.log 自然会转到控制台。如果您想将内容打印到控制台,请使用以下内容:

    request.server.log(['error', 'contentFetch'], err);

    这是我很好的插件配置,也许你可以放弃并找到适合你的东西。

    logging: {
            $filter: 'env',
            production: {
                reporters: {
                    file: [{
                        module: 'good-squeeze',
                        name: 'Squeeze',
                        args: [{error: '*', log: ['error'], ops: '*'}]
                    }, {
                        module: 'good-squeeze',
                        name: 'SafeJson',
                        args: [
                            null,
                            {separator: '\n'}
                        ]
                    }, {
                        module: 'rotating-file-stream',
                        args: [
                            'error.log',
                            {
                                size: '10M', // rotate every 10 MegaBytes written
                                interval: '1d',  // rotate daily
                                compress: 'gzip', // compress rotated files
                                path: './logs'
                            }
                        ]
                    }]
                }
            },
            $default: {
                ops: {
                    interval: 1000
                },
                reporters: {
                    console: [{
                        module: 'good-squeeze',
                        name: 'Squeeze',
                        args: [{log: '*', response: '*'}]
                    }, {
                        module: 'good-console'
                    }, 'stdout']
                }
            }
        },
    

    像这样注册

    {
            plugin: {
                register: 'good',
                options: Config.get('/logging')
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2020-07-24
      • 1970-01-01
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 2019-08-08
      • 2020-05-05
      • 2011-04-17
      相关资源
      最近更新 更多