AAkira / Napier

Logging library for Kotlin Multiplatform
Apache License 2.0
820 stars 36 forks source link

Double logging on Android LogCat makes Napier unusable #63

Closed chris-hatton closed 2 years ago

chris-hatton commented 3 years ago

For some reason, every Napier log in Androids LogCat is duplicated with these tags:

W/System.err <message>
I/DebugAntilog <message>

The double logging makes log output unreadable to the point I no longer want to use Napier. Are others experiencing this issue; and is there an easy resolution?

I/DebugAntilog is expected; I can't see why W/System.err is being logged: This is for all log levels, not just warnings or errors.

iOS logging is working as expected.

christianaye commented 3 years ago

it is a common java problem. there are two loggers registered. AntilogDebug add a new logger with default console handler to existing parent logger. you can change this behavior with following Kotlin code:

Napier.base(DebugAntilog("app", listOf(ConsoleHandler().apply {
    level = Level.INFO
    formatter = SimpleFormatter()
}))) // optional
val antilogLogger = Logger.getLogger(DebugAntilog::class.java.name)
antilogLogger.useParentHandlers = false

see last line. you have to set setUseParentHandlers to false see here

i think this should be documented in this project

chris-hatton commented 1 year ago

Why on earth would I want to write that boilerplate in every project, just to get sane logging on Android, or have to know that 'the anti-log logger mustn't use parent handlers'?

Libraries are meant to help, not hinder.

Also reconsider the term 'Antilog' - what does this even mean? The English interpretation of this would be 'opposite to logging, against logging'. Hardly encouraging naming. Kermit manages to make this friendly and easy, why doesn't Napier?