
// logger.js
const fs = require('fs');
const path = require('path');

// Ensure logs directory exists
defaultExport = null;
const logsDir = path.resolve(__dirname, 'logs');
if (!fs.existsSync(logsDir)) {
  fs.mkdirSync(logsDir);
}

// Paths for master and individual logs
const masterLogFile = path.join(logsDir, 'master.log');

/**
 * Append a log message to both the master log and the shop-specific log.
 * @param {string} shop - The shop identifier (e.g. domain) or 'general'.
 * @param {string} message - The message to log.
 */
function log(shop, message) {
  const now = new Date().toISOString();
  const line = `[${now}] [${shop}] ${message}\n`;
//console.log(line.trim()); // Log to console for real-time feedback
  // Write to master log
  fs.appendFileSync(masterLogFile, line, 'utf8');

  // Write to shop-specific log
  const shopLogFile = path.join(logsDir, `${shop.replace(/\W+/g, '_')}.log`);
  console.log(line)
  fs.appendFileSync(shopLogFile, line, 'utf8');
}

module.exports = { log };










// // logger.js
// const fs = require('fs');
// const path = require('path');

// function log(shop, message) {
//   const now = new Date().toISOString();
//   const line = `[${now}] ${message}\n`;

//   const logsDir = path.resolve(__dirname, 'logs');
//   if (!fs.existsSync(logsDir)) fs.mkdirSync(logsDir);

//   const filename = path.join(logsDir, `${shop.replace(/\W+/g, '_')}.log`);
//   fs.appendFileSync(filename, line, 'utf8');
// }

// module.exports = { log };
