I am using the google-cloud/logging-winston nodejs package for logging, and I created my custom formatter for output this way:
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}`));
It logs as expected, but there are funny characters before and after the log messages when viewed on Google cloud console. Below are some examples of the log:
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
I don't know what these mean: "[32m", "[31m" or "[39m" but they make it hard to read my logs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…