@@ -50,14 +50,19 @@ server.setErrorHandler((error, request, reply) => {
5050 if ( error . stack ) {
5151 const wrappedError = new Error ( error . message ) ;
5252 wrappedError . stack = error . stack ;
53- // important! the first parameter of log.error is the error object with an optional second parameter
54- // for the message.
53+ // For `request.log.error`, you can pass either:
54+ // 1. (errorMessageStr) — logs the error string if Error is not provided, or
55+ // 2. (Error) — logs the error object with its stack trace, or
56+ // 3. (Error, message) — logs both the structured error and a custom message.
57+ // This ensures proper parsing and correlation in the log pipeline.
5558 request . log . error ( wrappedError , `Request error: ${ error . message } ` ) ;
5659 } else {
57- // if the error is not an instance of Error, we should log it as a string. if first parameter is a string,
58- // then args from the second parameter are ignored. so always only log:
59- // one string parameter or (err,string) for request.log.error
60- // for request.log.info, pino only supports a single string parameter. this is important for logs to work.
60+ // ⚠️ If the error is not an instance of Error, log it as a plain string.
61+ // When the first argument is a string, any subsequent arguments are ignored.
62+ // For consistency:
63+ // - `request.log.error`: use either (Error, message) or a single string
64+ // - `request.log.info`: only supports a single string argument
65+ // These rules ensure correct log formatting and compatibility with our dashboards.
6166 request . log . error ( `Request error: ${ error . message } ` ) ;
6267 }
6368 if ( alreadySent ) {
@@ -88,13 +93,10 @@ server.addHook('onRequest', (request, reply, done) => {
8893
8994 request . startTime = Date . now ( ) ;
9095 if ( request . headers [ 'content-length' ] ) {
91- // for request.log.info, pino only supports a single string parameter or a serializable json
92- // with a `message` attribute like below. this is important for logs to work. you can put in url and other
93- // ewll known fields we support in our logging dashboard. you need not do this, only a string is needed and
94- // in dashboard the request id is injected with the log line. use object instead of string only for
95- // additional attributes like correlation id, url, size etc. these needs not be with every request as you
96- // can search all these with the request id in the dashboard to get context, so plain strings are
97- // recommended for logging info in most cases.
96+ // For request.log.info, Pino supports either a plain string or a JSON object with a `message` field.
97+ // Use a string message for most info logs — the request ID is automatically included in the dashboard.
98+ // Only use a JSON object when you need to attach extra metadata (e.g., correlationId, URL, size, etc.).
99+ // These fields are optional since you can always look up related context by request ID in the dashboard.
98100 request . log . info ( {
99101 message : 'Request size' ,
100102 reqId : request . id ,
0 commit comments