【发布时间】:2021-01-16 11:51:13
【问题描述】:
我正在使用 google-cloud/logging-winston nodejs 包进行日志记录,并以这种方式创建了用于输出的自定义格式化程序:
const winston = require('winston');
const { LoggingWinston } = require('@google-cloud/logging-winston');
const { format } = winston;
const { combine, label, json, timestamp, printf, colorize, simple } = format;
const path = require('path');
const customFormats = (category) => combine(
label({label: category}),
colorize({all: true}),
// simple()
timestamp(),
json(),
printf((info) => `${info.timestamp} - [${info.label?`${info.label}`:"NO_LABEL"}] - [${info.level}] : ${info.message}`));
它按预期记录,但在谷歌云控制台上查看时,日志消息前后有有趣的字符。以下是一些日志示例:
2021-01-16T10:58:00.836Z - [DEFAULT] - [[32minfo[39m] : [32mValidating route @/bills/airtime/send[39m
2021-01-16T10:58:00.841Z - [AIRTIME] - [[31merror[39m] : [31mAirtime recharge error Low account balance[39m
我不知道这些是什么意思:“[32m”、“[31m”或“[39m”,但它们让我很难阅读我的日志。
【问题讨论】:
标签: node.js google-cloud-platform winston google-cloud-logging