onjara / optic

A powerful logging framework for Deno
MIT License
44 stars 4 forks source link

Logger name not visible in default message format #4

Closed iacore closed 2 years ago

cknight commented 2 years ago

I'm not quite following this one? The default logger has a name of "default". You can see this here:

const logger = new Logger();
console.log("default logger name:", logger.name());

Outputs:

default logger name: default
iacore commented 2 years ago

I mean the logger name isn't shown in logged messages with default message format.

const logger = new Logger("abc")
logger.info("hi")
cknight commented 2 years ago

Logger names are somewhat niche and so aren't output by default. However, you can easily setup your console stream to output this. Here's how:

const logger = new Logger("abc");
const consoleStream = new ConsoleStream().withFormat(
  new TokenReplacer().withColor().withFormat(
    "{logger}: {dateTime} {level} {msg} {metadata}",
  ),
);
logger.addStream(consoleStream);

logger.info("hello world");

Outputs: abc: 2022-04-09T20:17:42.373Z Info hello world