{"action":"created","issue":{"url":"https://api.github.com/repos/pinojs/pino/issues/601","repository_url":"https://api.github.com/repos/pinojs/pino","labels_url":"https://api.github.com/repos/pinojs/pino/issues/601/labels{/name}","comments_url":"https://api.github.com/repos/pinojs/pino/issues/601/comments","events_url":"https://api.github.com/repos/pinojs/pino/issues/601/events","html_url":"https://github.com/pinojs/pino/issues/601","id":412444511,"node_id":"MDU6SXNzdWU0MTI0NDQ1MTE=","number":601,"title":"Logging request id","user":{"login":"Karina246","id":47789225,"node_id":"MDQ6VXNlcjQ3Nzg5MjI1","avatar_url":"https://avatars0.githubusercontent.com/u/47789225?v=4","gravatar_id":"","url":"https://api.github.com/users/Karina246","html_url":"https://github.com/Karina246","followers_url":"https://api.github.com/users/Karina246/followers","following_url":"https://api.github.com/users/Karina246/following{/other_user}","gists_url":"https://api.github.com/users/Karina246/gists{/gist_id}","starred_url":"https://api.github.com/users/Karina246/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Karina246/subscriptions","organizations_url":"https://api.github.com/users/Karina246/orgs","repos_url":"https://api.github.com/users/Karina246/repos","events_url":"https://api.github.com/users/Karina246/events{/privacy}","received_events_url":"https://api.github.com/users/Karina246/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-02-20T14:09:38Z","updated_at":"2019-02-20T22:18:17Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nI’m using Pino with Fastify and I like to have a request id property in all logs that occur during the request lifecycle.\r\n\r\nI’ve set the genReqId option like:\r\n```js\r\nlogger.genReqId = function(request) {\r\n    const requestId = request.headers['x-request-id'] || uuid();\r\n    return requestId;\r\n  };\r\n```\r\n\r\nAnd when I’m using req.log.info everything seems to work!\r\n\r\nBut I don’t want to pass the req.log as an argument to all the functions in the system that needs to log.  I want to write my logs in the form of logger.info, So I’m looking for a different solution. \r\n\r\nOne thing I had in mind is when creating a new instance of the logger to do something like this:\r\n\r\n```js\r\nconst logger = pino({\r\n  base: { \r\n    request_id: () => uuid()\r\n  }\r\n});\r\n```\r\n\r\nAnd when I log a message, the request_id function will be evaluated at log time.\r\n\r\nCurrently the behaviour is that the base properties are evaluated once at the construction time.\r\n\r\nAny ideas?"},"comment":{"url":"https://api.github.com/repos/pinojs/pino/issues/comments/465777778","html_url":"https://github.com/pinojs/pino/issues/601#issuecomment-465777778","issue_url":"https://api.github.com/repos/pinojs/pino/issues/601","id":465777778,"node_id":"MDEyOklzc3VlQ29tbWVudDQ2NTc3Nzc3OA==","user":{"login":"mcollina","id":52195,"node_id":"MDQ6VXNlcjUyMTk1","avatar_url":"https://avatars0.githubusercontent.com/u/52195?v=4","gravatar_id":"","url":"https://api.github.com/users/mcollina","html_url":"https://github.com/mcollina","followers_url":"https://api.github.com/users/mcollina/followers","following_url":"https://api.github.com/users/mcollina/following{/other_user}","gists_url":"https://api.github.com/users/mcollina/gists{/gist_id}","starred_url":"https://api.github.com/users/mcollina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcollina/subscriptions","organizations_url":"https://api.github.com/users/mcollina/orgs","repos_url":"https://api.github.com/users/mcollina/repos","events_url":"https://api.github.com/users/mcollina/events{/privacy}","received_events_url":"https://api.github.com/users/mcollina/received_events","type":"User","site_admin":false},"created_at":"2019-02-20T22:18:17Z","updated_at":"2019-02-20T22:18:17Z","author_association":"MEMBER","body":"> P.S. @Karina246 on second thought you could create a child logger for every request and put it inside cls context, then get it later in your controller or anywhere else withing your request, but it seems rather ugly.\r\n\r\nFastify already creates a child logger for every request. If you want to fetch such logger, you can easily store it in cls-hooked, and get the logger from there."}}
{"actor":{"display_login":"mcollina"}}