DataDog / browser-sdk

Datadog Browser SDK
Apache License 2.0
303 stars 132 forks source link

💡 [datadogLogs] Customizable levels per logger's handler type #3100

Open morzel85 opened 1 week ago

morzel85 commented 1 week ago

It is possible to setup both console and http handler for a logger, but AFAIK it is not possible to configure different levels for the handlers.

I would like to have debug level for console and info for http (more data in browser console, less data on DD servers).

My current workaround is to have the level defined as debug and using beforeSend event to filter out debug level messages from sending to DD servers, it works but more explicit/declarative API would be nice.

cy-moi commented 1 week ago

Hi @morzel85 ,

Thank you for reaching out. Are you looking for the configuration forwardConsoleLogs? It provides the ability to forward console logs at different levels.

morzel85 commented 6 days ago

If I were to switch to log forwarding, then all the console calls (of certain level) would be captured, right? The issue here is that some entries to console are inserted by code outside of my control, hence the preference to use DD logger.

amortemousque commented 1 day ago

Hello @morzel85, One way to have different levels for the handlers could be to create different loggers with the createLogger API. Let me know if that answer your question.

morzel85 commented 1 day ago

Using two different loggers would be more complex than the beforeSend filter 'trick' I use now. With single logger, the code that does the logging (creates entries) doesn't need to be aware of any destination config.