const options = { year: 'numeric', day: '2-digit', month: '2-digit', hour: '2-digit', 'minute': '2-digit', second: '2-digit' };
const osLocale = (process.env.LANG || process.env.LANGUAGE || process.env.LC_ALL || process.env.LC_MESSAGES).split('.')[0].replace('_', '-');
const dtFormat = Intl.DateTimeFormat(osLocale, options);

/**
 * Gets formatted timestamp
 * @returns {string} timestamp string
 */
export const getTime = () => {
  return dtFormat.format(new Date());
}

/**
 * Logs formatted output to the console
 * @param {string} src the source script doing the logging
 * @param {string} msg the message to log
 */
export const log = (src, msg) => {
  const time = getTime();
  console.log(`${time} : ${src} : ${msg.toString().trim()}`);
};

/**
 * Logs formatted output to the console as an error
 * @param {string} src the source script doing the logging
 * @param {string} msg the message to log
 */
export const error = (src, msg) => {
  const time = getTime();
  console.error(`\x1b[33m${time} : ${src} : ${msg.toString().trim()}\x1b[0m`);
}