# All files / src/logger index.ts

80% Statements 4/5
37.5% Branches 3/8
100% Functions 2/2
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29

    42x

    42x

    358x

     import pino from 'pino';

    function resolveLevel(): string {
      Eif (process.env.CW_LOG_LEVEL) return process.env.CW_LOG_LEVEL;
      return process.env.NODE_ENV === 'development' ? 'debug' : 'info';
    }

    export const logger = pino(
      {
        name: 'cw',
        level: resolveLevel(),
        ...(process.env.CW_LOG_PRETTY === '1' && {
          transport: {
            target: 'pino-pretty',
            options: {
              colorize: true,
              ignore: 'pid,hostname',
              translateTime: 'HH:MM:ss.l',
            },
          },
        }),
      },
      process.env.CW_LOG_PRETTY === '1' ? undefined : pino.destination(2),
    );

    export function createModuleLogger(module: string) {
      return logger.child({ module });
    }