import pino from 'pino';
import pinoPretty from 'pino-pretty';
import path from 'path';

const log_level = process.env.PROD === undefined ? "debug" : "info";

export const log = pino({
  level: log_level,
  prettyPrint: {
    levelFirst: true,
    colorize: true,
    singleLine: true,
    ignore: "module",
    messageFormat: "{levelLabel}[{pid}] {module}: {msg}"
  },
  prettifier: pinoPretty
});

export const create = (import_url) => {
  const pd = path.parse(import_url);
  const log_line = `${path.basename(pd.dir)}/${pd.base}`;
  return log.child({module: log_line});
}

export default { create, log };
