I have golang based lambda function which does some work and logs the information during execution.
I'm using zapcore Golang logger as below
func NewLogger(logLevel string) (*zap.SugaredLogger, error) {
encoderConfig := zapcore.EncoderConfig{
TimeKey: "Time",
LevelKey: "Level",
NameKey: "Name",
CallerKey: "Caller",
MessageKey: "Msg",
StacktraceKey: "St",
EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
consoleEncoder := zapcore.NewConsoleEncoder(encoderConfig)
consoleOut := zapcore.Lock(os.Stdout)
var level zap.AtomicLevel
err := level.UnmarshalText(([]byte(logLevel)))
if err != nil {
level.UnmarshalText([]byte(defaultLogLevel))
}
core := zapcore.NewTee(zapcore.NewCore(
consoleEncoder,
consoleOut,
level,
))
logger := zap.New(core)
Logger = logger.Sugar()
return Logger, nil
}
However when it generates the logs in CloudWatch, I see an extra character in the logs.
2022-06-30T21:52:43.310-07:00 2022-07-01T04:52:43.310Z [34mINFO[0m Process my event
- Why the logs is getting generated with [34m and [0m string in it?
- Do I really need to generate logs with timestamp because I see cloudwatch already adds timestamp to logs.