scala-logging
scala-logging copied to clipboard
Custom logger
In my project I want to have custom logger, based on scala-logging Logger
class. But for now there is no possibility to create custom logger. Logger
class is final and with private construstor.
I have tried some experiments in fork, but macroses makes all inheritance stuff very complicated.
Can you explain your use case for a custom logger?
In my project in some classes I need to wrap all logger calls with MDC.put
and MDC.remove
calls. It would be cool if I will have a possibility to add this boilerplate calls inside custom logger.
We have a similar situation in our project. We have a custom ThrottledLogger extends Logger - the old trait which is available in version 2.1.2. All classes use that trait and we can choose to supply normal or throttled logger.
Now that trait has gone in the latest version, there is no common trait to use unless we hand crank our own version.
Via Patrick Premont: I think this wouldn’t help those who want to override the macros. They would need to ensure their subclass is used explicitly everywhere. Any reference to the base class would not get the overridden behaviour. So it would be safer for their type not to extend Logger, to avoid such accidents. I created a gist to highlight the compile-time dispatch that occurs with the macro override: https://gist.github.com/patrick-premont/01c5847958e1776d7748bb9570ee376e