const pino = require('pino');

const PinoLevelToSeverityLookup = {
  trace: 'DEBUG',
  debug: 'DEBUG',
  info: 'INFO',
  warn: 'WARNING',
  error: 'ERROR',
  fatal: 'CRITICAL',
};

const logger = (defaultConfig) =>
  pino({
    ...defaultConfig,
    messageKey: 'message',
    formatters: {
      level(label, number) {
        return {
          severity:
            PinoLevelToSeverityLookup[label] ||
            PinoLevelToSeverityLookup['info'],
          level: number,
        };
      },
    },
    mixin: () => ({ name: 'custom-pino-instance' }),
  });

module.exports = {
  logger,
};
