Bunyan 对象控制台日志记录 vi CLI

时间:2021-03-12 04:21:43

标签: node.js logging bunyan

希望今天是一个简单的。

我有一个简单的班扬脚本设置来做一些日志

import * as bunyan from 'bunyan'
import { LoggerOptions } from 'bunyan'

export const Logger = (config: LoggerOptions) => {
  return bunyan.createLogger(config)
}

然后登录我只是这样做

import Logger from './logger.ts'

const config = {
  host: '127.0.0.1',
  port: 2000,
  logger: { 
    name: 'Free Flowing Logs' 
  }
}

const Logger = Logger(config.logger)

Logger.info(config)

这给了我以下输出

日志 1

04:16:07.784Z  INFO Free Flowing Logs:  (host=127.0.0.1, port=2000)
    logger: {
      "name": "Free Flowing Logs"
    }

我真正想要的是它在登录到控制台时更像 console.log,所以

日志 2

04:16:07.784Z  INFO Free Flowing Logs: 
  {
    host: '127.0.0.1',
    port: 2000,

    logger: {
      "name": "Free Flowing Logs"
    }

注意日志 1 与日志 2 的第一行。

用 bunyan 可以吗?

0 个答案:

没有答案