dahlia / logtape

Simple logging library with zero dependencies for Deno, Node.js, Bun, browsers, and edge functions
http://logtape.org/
MIT License
520 stars 11 forks source link

How to log curly braces or disable placeholders? #1

Closed windupbird144 closed 6 months ago

windupbird144 commented 6 months ago

I want to log messages with curly braces. Here's a minimal code example.

import { configure, getLogger } from "@logtape/logtape";

await configure({
  sinks: {
    console: (record) => {
      console.log(record);
    },
  },
  loggers: [
    {
      category: "default-logger",
      sinks: ["console"],
    },
  ],
  filters: {},
});

const logger = await getLogger("default-logger");

logger.debug("Hello {world}");

This logs

{
  message: [ "Hello ", undefined, "" ],
  // Omitted for brevity
}

But I want to log

{
  message: "Hello {world}"
  // Omitted for brevity
}

If I don't want to use placeholders, is it possible to

If you are open to contributions I'd be willing to write a PR for this.

dahlia commented 6 months ago

disable a placeholder once, e.g. with an escape character

Currently LogTape has no way to do this. The way to escape curly braces would be nice to have.

disable the use of placeholders entirely, e.g. in the call to configure

You can use a template literal syntax, e.g.:

logger.debug `Hello {world}`;
dahlia commented 6 months ago

It would be nice to make the escaping syntax overlapping curly braces, similar to the formatting syntax in C#/Python, e.g.:

logger.debug("Hello {{world}}");