scala-logging icon indicating copy to clipboard operation
scala-logging copied to clipboard

Custom logger

Open LMnet opened this issue 9 years ago • 4 comments

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.

LMnet avatar Dec 03 '15 10:12 LMnet

Can you explain your use case for a custom logger?

analytically avatar Apr 15 '16 21:04 analytically

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.

LMnet avatar Apr 16 '16 05:04 LMnet

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.

zatekusen avatar Dec 14 '16 09:12 zatekusen

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

analytically avatar Jul 04 '17 15:07 analytically