Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble understanding the level property on loggers #26

Closed
Callumk7 opened this issue Nov 17, 2024 · 7 comments
Closed

Trouble understanding the level property on loggers #26

Callumk7 opened this issue Nov 17, 2024 · 7 comments

Comments

@Callumk7
Copy link

export async function setupLogging() {
	await configure({
		sinks: {
			console: getConsoleSink({
				formatter: ansiColorFormatter,
			}),
			jsonl: getFileSink("log.jsonl", {
				formatter: (record) => `${JSON.stringify(record)}\n`,
			}),
			db: getFileSink("db-log.jsonl", {
				formatter: (record) => `${JSON.stringify(record)}\n`,
			}),
		},
		loggers: [
			{
				category: ["hono"],
				level: "info",
				sinks: ["jsonl"],
			},
			{
				category: ["hono", "debug"],
				level: "debug",
				sinks: ["console"],
			},
			{
				category: ["hono", "db"],
				level: "debug",
				sinks: ["db"],
			},
		],
	});
}

With the above setup, I would expect that a logger created using getLogger(["hono", "db", "some-module"] to log INFO and above to both jsonl and db sinks, but any DEBUG logs to only be sent to the db sink.

In reality, all logs are sent to both sinks.

This is the same for a logger with category ["hono", "console", "something"]; I wouldn't expect debug logs to be sent to jsonl, but they are.

Using parentSink: override works as expected: all levels of logs are sent to the correct sink, nothing is sent to jsonl.

Can you help me understand how I can set this up correctly?

@dahlia
Copy link
Owner

dahlia commented Nov 18, 2024

No, you're not wrong in your understanding. It appears to be a bug in LogTape, which I'll get fixed soon.

@dahlia dahlia added the bug Something isn't working label Nov 18, 2024
@dahlia
Copy link
Owner

dahlia commented Nov 18, 2024

One workaround you can use right now is to use sink filters.

@dahlia
Copy link
Owner

dahlia commented Nov 19, 2024

Upon further reflection, I don't think it's a bug, but I realized that the current configuration syntax is easy to misunderstand. I'll try to fix the configuration syntax in the next version.

@dahlia dahlia removed the bug Something isn't working label Nov 19, 2024
@Callumk7
Copy link
Author

Thanks for looking into it. I will check out sink filters.

Again I might be misunderstanding, but this section of the docs:

https://logtape.org/manual/levels#configuring-severity-levels

Has an example that seems to imply the behaviour outlined in my first comment would be correct:

await configure({
  // ... other configuration ...
  loggers: [
    {
      category: ["app"],
      level: "info",  // This will log info and above
    },
    {
      category: ["app", "database"],
      level: "debug",  // This will log everything for database operations
    }
  ]
});

It is only a small section though, but the comments do seem to imply that the baseline logger won't log debug logs. If that is not the case, it might be worth reviewing or removing this section of the docs.

@dahlia
Copy link
Owner

dahlia commented Nov 19, 2024

That section is incorrectly described, I'll fix it… 😓

@Callumk7
Copy link
Author

Thanks for your help! Filters work great, and otherwise I really enjoy the API so far

@dahlia dahlia closed this as completed in 24252bf Nov 20, 2024
@dahlia
Copy link
Owner

dahlia commented Nov 20, 2024

Since LogTape 0.8.0, the level option is deprecated in favor of the new lowestLevel option. See also the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants