【问题标题】:Disable hostname in fastify logs with Pino使用 Pino 在 fastify 日志中禁用主机名
【发布时间】:2022-08-17 01:05:55
【问题描述】:

我发现 Pino 提供了一种机制来删除这个 through an option called base 但似乎无法通过 fastify 日志配置获得。使用默认的 fastify 记录器但从所有日志行中删除主机名的最佳方法是什么?

作为示例,这里有一些使用默认 fastify 记录器的输出:

{\"level\":30,\"time\":1660583707685,\"pid\":17,\"hostname\":\"goldsky-api-7cf949f758-zzpf2\",\"msg\":\"Server listening at http://0.0.0.0:80\"}

我想删除自动注入此日志行的hostname

编辑:FastifyLoggerOptions 似乎没有为 pino base 选项提供字段,这意味着如果我尝试通过该选项,打字稿编译将失败。

    标签: fastify


    【解决方案1】:

    logger 选项被转发到 fastify 的 pino 实例:

    const fastify = require('fastify')({
      logger: {
        // pino options
        base: false,
      },
    })
    fastify.get('/', async (request, reply) => {
      return { hello: 'world' }
    })
    fastify.inject('/')
    

    【讨论】:

      猜你喜欢
      • 2012-04-04
      • 1970-01-01
      • 2020-09-17
      • 2020-08-04
      • 2022-08-17
      • 2020-08-31
      • 2022-01-12
      • 2017-04-25
      • 1970-01-01
      相关资源
      最近更新 更多