-
Notifications
You must be signed in to change notification settings - Fork 983
1.4 to 2.0 Migration Tips
trentm edited this page Oct 5, 2012
·
15 revisions
Symptom: You might see the following error:
/opt/smartdc/imgapi/node_modules/bunyan/lib/bunyan.js:365
throw new TypeError(format(
^
TypeError: invalid serializer for "res" field: must be a function
at .../node_modules/bunyan/lib/bunyan.js:365:15
at Array.forEach (native)
at addSerializers (.../node_modules/bunyan/lib/bunyan.js:362:30)
at new Logger (.../node_modules/bunyan/lib/bunyan.js:392:5)
at Function.createLogger (.../node_modules/bunyan/lib/bunyan.js:1085:10)
at handleArgv (.../main.js:120:18)
at main (.../main.js:154:16)
...
at Object.Module._extensions..js (module.js:467:10)
In restify 1.4 restify.bunyan.serializers
includes a response
field that you'd want to use like this:
var log = bunyan.createLogger({
name: 'whatever',
serializers: {
res: restify.bunyan.serializers.response,
req: bunyan.stdSerializers.req,
err: bunyan.stdSerializers.err,
...
},
...
});
In restify 2.0 the keys restify.bunyan.serializers
actually match well-known log record field names (req
for a request, res
for a response). Also, restify includes more serializers (client_req
and client_res
are new) and re-exports the bunyan stdSerializers (at least the current set). Typical usage would now be:
var log = bunyan.createLogger({
name: 'whatever',
serializers: restify.bunyan.serializers,
...
});
Slightly less convenient if you have your own custom serializers, but generally a win.