const format = (level, message, context) => {
  const payload = {
    level,
    message,
    timestamp: Date.now(),
    ...(context ? { context } : {})
  };
  return JSON.stringify(payload);
};

export const logger = {
  info(message, context) {
    process.stdout.write(`${format('info', message, context)}\n`);
  },
  warn(message, context) {
    process.stdout.write(`${format('warn', message, context)}\n`);
  },
  error(message, context) {
    process.stderr.write(`${format('error', message, context)}\n`);
  }
};
