I am using cosmas@2.0.0 and provided express hook.
Given following option passed to cosmas initialization
config: {
serializers: {
req(req) {
req.body = 'mystring';
return loggerSerializers.req(req); // loggerSerializers = require('cosmas/dist/serializers').serializers;
},
res(res) {
return loggerSerializers.res(res);
},
},
},
It produces following log:
{"level":50,"severity":"ERROR","time":"2020-06-26T10:50:37.082Z","req":{"body":{"0":"m","1":"y","2":"s","3":"t","4":"r","5":"i","6":"n","7":"g"},"headers":{"user-agent":"PostmanRuntime/7.25.0"},"method":"POST","url":"/trips"},"res":{"time":"1134.818"},"userAgent":"PostmanRuntime/7.25.0","cosmas.pkgVersion":"2.0.0","message":"500 POST /trips - Standard output"}
The problem is in serializing the body as
"body":{"0":"m","1":"y","2":"s","3":"t","4":"r","5":"i","6":"n","7":"g"}
In the serializer, if I set the body as an object like this
req.body = { s: 'mystring' };
body gets logged correctly
I am using cosmas@2.0.0 and provided express hook.
Given following option passed to cosmas initialization
It produces following log:
{"level":50,"severity":"ERROR","time":"2020-06-26T10:50:37.082Z","req":{"body":{"0":"m","1":"y","2":"s","3":"t","4":"r","5":"i","6":"n","7":"g"},"headers":{"user-agent":"PostmanRuntime/7.25.0"},"method":"POST","url":"/trips"},"res":{"time":"1134.818"},"userAgent":"PostmanRuntime/7.25.0","cosmas.pkgVersion":"2.0.0","message":"500 POST /trips - Standard output"}The problem is in serializing the body as
In the serializer, if I set the body as an object like this
body gets logged correctly