logger.js 664 B

12345678910111213141516171819202122
  1. const pino = require('pino');
  2. /**
  3. * Create a structured pino logger bound to a service name.
  4. * Pass the returned instance to Fastify as { logger: log } so that
  5. * app.log and the request-level child loggers all share the same config.
  6. *
  7. * Standard fields emitted on every line: service, level, time, msg
  8. * Callers should add: action, platform, outcome, err (and any extras).
  9. */
  10. function createLogger(service) {
  11. return pino({
  12. level: process.env.LOG_LEVEL || 'info',
  13. base: { service },
  14. timestamp: pino.stdTimeFunctions.isoTime,
  15. formatters: {
  16. level(label) { return { level: label }; },
  17. },
  18. });
  19. }
  20. module.exports = { createLogger };