Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Different logging strategy for error/info #212

Open
kosiara opened this issue Sep 5, 2018 · 0 comments
Open

[Suggestion] Different logging strategy for error/info #212

kosiara opened this issue Sep 5, 2018 · 0 comments

Comments

@kosiara
Copy link

kosiara commented Sep 5, 2018

  • Logger version: 2.2.0

I would like to log error/info with a different FormatStrategy. Info should be logged with only the message body and errors with body and stacktrace.
i.e. for info messages:

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ This is a sample info log content -> 123
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────

and error messages like so:

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ Thread: main
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ NativeMethodAccessorImpl.invoke  (NativeMethodAccessorImpl.java:62)
│    NativeMethodAccessorImpl.invoke0  (NativeMethodAccessorImpl.java:-2)
│       AALogTest.logError  (AALogTest.kt:39)
│          AALog.e  (AALog.kt:19)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ This is a sample error 123123:4321 ## @@
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Could LoggerPrinter class be made public so that one can inherit from it?

When LoggerPrinter is public the following implementation would be possible:

/**
 * Logging interface implementation 
 */
object AALogImpl {

    private lateinit var errorLogger: LoggerPrinter
    private lateinit var infoLogger: LoggerPrinter

    fun init() {
        errorLogger = createLogger(true)
        infoLogger = createLogger(false)
    }

    private fun createLogger(showStackTrace: Boolean): LoggerPrinter {
        return LoggerPrinter().withAdapter(AndroidLogAdapter(PrettyFormatStrategy.newBuilder()
            .showThreadInfo(showStackTrace)
            .logStrategy(McLogcatLogStrategy())
            .methodCount(if (showStackTrace) 4 else 0)
            .methodOffset(if (showStackTrace) 4 else 0)
            .tag("MY_CUSTOM_TAG")
            .build()))
    }

    fun e(msg: String) = errorLogger.e(msg)

    fun i(msg: String) = infoLogger.i(msg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant