Napier icon indicating copy to clipboard operation
Napier copied to clipboard

logs are printed twice

Open emanuelecastelli opened this issue 1 year ago • 4 comments

Hi, after upgrading KMM project to Kotlin 2.0.21 we are experiencing a strange problem: logs are written twice. Basically fun performLog get called twice (i have extended base AntiLog for better control over flow). Did you have experienced same problem or did you have any idea on how to deal with this?

Thx

ps: i have tested just ios

emanuelecastelli avatar Oct 17 '24 13:10 emanuelecastelli

Make sure your Napier was not call initialized twice...

rosuH avatar Dec 07 '24 03:12 rosuH

The same I see in Android, with Kotlin 2.0 on Multiplatform. All log messages are duplicated.

ivanovpv avatar Feb 18 '25 10:02 ivanovpv

So you can't call Napier.base() more than once? I want to change the logging implementation on the fly. Something like this:

override fun attachBaseContext(base: Context?) {
   // I need logging as soon as possible to catch loggin during initialization (e.g., before hilt runs dependency injection)
   Napier.base(DebugAntiLog())
   Timber.plant(NapierTree())
   super.attachBaseContext(base)
}

override fun onCreate() {
     super.onCreate()
     // we need initialization to be complete to set up the crashlytics logging.
     Napier.base(CrashlyticsAntiLog())
}

mandrachek avatar Aug 22 '25 18:08 mandrachek

@mandrachek The quickest solution is to use a proxy in DebugAntiLog. After CrashlyticsAntiLog has been initialized, you can set the proxy to CrashlyticsAntiLog.

rosuH avatar Aug 24 '25 01:08 rosuH