logtape icon indicating copy to clipboard operation
logtape copied to clipboard

`logtape·meta` logs unexpectedly

Open raine opened this issue 1 year ago • 4 comments

Hi,

If you are seeing this message, the meta logger is somehow configured.

I don't see how I'm configuring meta logger in this example I derived from the documentation.

Am I doing something wrong? Thanks.

Latest version from npm. Happy to provide more details as needed.

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

await configure({
  sinks: { console: getConsoleSink() },
  loggers: [
    {
      category: "my-app",
      level: "info",
      sinks: ["console"],
    },
  ],
})

const logger = getLogger(["my-app"])
logger.info("foo")

> tsx main.ts

10:51:57.989 INF logtape·meta LogTape loggers are configured.  Note that LogTape itself uses the meta logger, which has category [ 'logtape', 'meta', [length]: 2 ].  The meta logger purposes to log internal errors such as sink exceptions.  If you are seeing this message, the meta logger is somehow configured.  It's recommended to configure the meta logger with a separate sink so that you can easily notice if logging itself fails or is misconfigured.  To turn off this message, configure the meta logger with higher log levels than 'info'.
10:51:57.990 INF my-app foo

raine avatar Oct 10 '24 10:10 raine

To turn off this message, configure the meta logger with higher log levels than 'info'.

You can suppress it by configuring the meta logger with a higher log level than "info":

await configure({
  sinks: { console: getConsoleSink() },
  loggers: [
    {
      category: ["logtape", "meta"],
      level: "warning",
      sinks: ["console"],
    },
    {
      category: "my-app",
      level: "info",
      sinks: ["console"],
    },
  ],
});

dahlia avatar Oct 10 '24 11:10 dahlia

Thanks for the reply, I appreciate it.

However I find this unintuitive and not a great first impression.

The log message says:

If you are seeing this message, the meta logger is somehow configured.

This implies I have somehow configured it by mistake, and that it's not a default behavior of the library (which it seems to be?).

Additionally, why do the internals of this logging library log something by default? This is not a behavior I've ever seen with other logging libraries and comes off as a bug.

raine avatar Oct 10 '24 13:10 raine

If you are seeing this message, the meta logger is somehow configured.

This implies I have somehow configured it by mistake, and that it's not a default behavior of the library (which it seems to be?).

Indeed that's misleading. It's probably because English is not my first language. I'll adjust the message.

Additionally, why do the internals of this logging library log something by default? This is not a behavior I've ever seen with other logging libraries and comes off as a bug.

As sometimes a sink can fail to record a log message, I think such meta logs should be recorded and shown to users. 🤔

dahlia avatar Oct 11 '24 03:10 dahlia

Understood, thanks again.

For what it's worth, given the earlier example, I think the least surprising outcome is to see just:

10:51:57.990 INF my-app foo

If I'm setting up a logger, especially a library I'm not that familiar with, I would like there to be minimal noise & mental overhead and not have to worry about how to hide the internal meta logs or what they mean.

Just my 2c 🙏

raine avatar Oct 11 '24 13:10 raine

I'm trying out the library and ran across this as well. Wasn't straight forward to find out how to disable the meta logger. Maybe this can be included in the quick start docs? Right now it is in the last section under "categories" - https://logtape.org/manual/categories#meta-logger

Personally, I think the meta logger should be disabled by default with an option to enable it when we call configure.

w3cj avatar Oct 13 '24 20:10 w3cj