const { logEnabled } = require('./env');

function log(scope, message, data) {
  if (!logEnabled) return;
  const suffix = data === undefined ? '' : ` ${format(data)}`;
  console.log(`[PhotoRenamer:${scope}] ${message}${suffix}`);
}

function error(scope, message, err) {
  if (!logEnabled) return;
  const detail = err && err.stack ? err.stack : err;
  console.error(`[PhotoRenamer:${scope}] ${message}`, detail);
}

function format(data) {
  try {
    return JSON.stringify(data);
  } catch {
    return String(data);
  }
}

module.exports = { error, log };
