import pino from 'pino';

// Initialize Pino logger
const targets = [];

// Console logging (pretty-printed in development)
if (process.env.NODE_ENV !== 'production')
{
  targets.push({
    target: 'pino-pretty',
    options: {
      colorize: true
    },
    level: process.env.LOG_LEVEL || 'info'
  });
}
else
{
  // Basic console logging in production
  targets.push({
    target: 'pino/file', // Log to stdout in production
    options: { destination: 1 }, // 1 is stdout
    level: process.env.LOG_LEVEL || 'info'
  });
}

// Database logging via custom transport
targets.push({
  target: './prisma-pino-transport.js', // Path to the custom transport
  options: {}, // No specific options needed for this transport
  level: process.env.DB_LOG_LEVEL || 'info' // Separate level for DB logging if needed
});

export const logger = pino({
  level: process.env.LOG_LEVEL || 'info', // Overall minimum level
  transport: {
    targets: targets
  }
});