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

LogLevel in a worker environment doesn't log to console #202

Open
cmcnicholas opened this issue Dec 5, 2024 · 1 comment
Open

LogLevel in a worker environment doesn't log to console #202

cmcnicholas opened this issue Dec 5, 2024 · 1 comment

Comments

@cmcnicholas
Copy link

In a regular web application I can simply:

import * as logger from 'loglevel';

logger.info('hello world');

the same code when executed in a Worker or SharedWorker does not log to console, instead I have to logger.getLogger('somelogger').info('hello world') to achieve the same effect, this makes working with a global logger instance difficult as any methods using the logger need to now accept it as an instance in a worker.

@Mr0grog
Copy link
Contributor

Mr0grog commented Dec 5, 2024

Can you share a complete, working example of this? I’m not sure how to reproduce it.

Since the default level is WARN, this shouldn’t normally log anything in any environment. I assume you either have a saved level (which a worker may not have access to) or you are calling setLevel() or setDefaultLevel() somewhere else in your code before calling logger.info(...). Loglevel doesn’t have native support for import, either, so there might also be an issue caused by whatever builder/bundler you’re using.

If I change your example to use logger.warn() and build the worker script with esbuild, it works fine for me, but that obviously doesn’t match whatever your complete setup is.

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