import winston from 'winston';
import path from 'path';

export function createLogger(service) {
  return winston.createLogger({
    level: process.env.LOG_LEVEL || 'info',
    format: winston.format.combine(
      winston.format.timestamp(),
      winston.format.json()
    ),
    defaultMeta: { service },
    transports: [
      // Write all logs to console
      new winston.transports.Console({
        format: winston.format.combine(
          winston.format.colorize(),
          winston.format.simple()
        )
      }),
      // Write all logs to service-specific files
      new winston.transports.File({
        filename: path.join('logs', `${service}-error.log`),
        level: 'error'
      }),
      new winston.transports.File({
        filename: path.join('logs', `${service}-combined.log`)
      })
    ]
  });
} 