Better name for Logging Levels

2021-03-23

I find logging levels quite difficult to understand and use. What’s informative? versus what is a warning?

I’ve seen this naming scheme somewhere a while ago, (ref required), I wished this was more common:

export const makeLogger = (name: string) => {
  const prefix = `[${name}]`;

  return {
    inTestEnv: (msg: string, ...args: any[]) =>
      console.debug(`${prefix}: ${msg}`, ...args),
    inProdEnv: (msg: string, ...args: any[]) =>
      console.info(`${prefix}: ${msg}`, ...args),
    toInvestigateTomorrow: (msg: string, ...args: any[]) =>
      console.warn(`${prefix}: ${msg}`, ...args),
    wakeMeUpInTheMiddleOfTheNight: (msg: string, ...args: any[]) =>
      console.error(`${prefix}: ${msg}`, ...args),
    makeLogger: (subName: string) => makeLogger(`${name}.${subName}`),
  };
};

Laurent Senta

I wrote software for large distributed systems, web applications, and even robots. I love the technical challenges, but I worry about privacy-invading ecosystems. Now I care about decentralization, overly-engineered software, and frugal innovation. I help companies around the world build products through SingularGarden.