Skip to content

Changes in 1.0.1 seems to have broken my logger #20

@gitblit

Description

@gitblit

Given this logger...

import { Logestic, chalk } from "logestic";

// exports a Logestic plugin instance
export const logger = new Logestic({ showLevel: true })
  .use(["time", "method", "path", "status", "duration"])
  .format({
    // onRequest({ time, method, path }) {
    //   const grayTime = chalk.gray(`${time!.toISOString()}`);
    //   const methodPath = chalk.cyan(`${method} ${path}`);

    //   return `[${grayTime}] 🟢 ${methodPath}`;
    // },
    onSuccess({ time, method, path, status, duration }) {
      const grayTime = chalk.gray(`${time!.toISOString()}`);
      const methodPath = chalk.cyan(`${method} ${path}`);
      let statusColor = chalk.white;

      if (200 <= status && status < 300) statusColor = chalk.green;
      if (400 <= status && status < 500) statusColor = chalk.yellow;
      if (500 <= status) statusColor = chalk.red;

      const durationInMsecs = chalk.magenta(`${(duration ?? 0n) / 1000n}`);

      return `[${grayTime}] 🛑 ${methodPath} | ${statusColor(status)} | ${durationInMsecs} ms\n`;
    },
    onFailure({ request, error, code, datetime }) {
      const log = chalk.red(`[${datetime.toISOString()}]: ${request.method} ${request.url} | ERROR | ${code}`);
      return `${log}\n${error}`;
    },
});

I get undefined errors on time. If I replace the time reference in the string interpolation with (new Date()) then I get undefined on every argument in the onSuccess console logs. I have determined that this behavior change was introduced in 1.0.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions