designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

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

Open morzel85 opened this issue 1 year ago • 5 comments

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.

morzel85 avatar Oct 28 '24 21:10 morzel85

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.

cy-moi avatar Oct 29 '24 14:10 cy-moi

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.

morzel85 avatar Oct 30 '24 09:10 morzel85

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.

amortemousque avatar Nov 04 '24 15:11 amortemousque

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.

morzel85 avatar Nov 04 '24 21:11 morzel85

@morzel85, I understand that using beforeSend might be more convenient in your case, and I think it’s a good workaround. I’ll let you know when we have an alternative solution for this.

amortemousque avatar Nov 07 '24 14:11 amortemousque