ConsoleLogger

class ConsoleLogger(val minLogLevel: Level = Level.VERBOSE, val filter: LumberjackFilter = DefaultLumberjackFilter, val tagTransformer: (tag: String?) -> String? = { it }) : ILumberjackLogger

Console logger that writes logs to the platform console and allows transforming the runtime tag.

This logger is useful on platforms that produce a lot of internal logs (e.g. certain Android devices). The tagTransformer function lets callers format, shorten, sanitize, prefix, or completely replace the runtime tag before it is passed to the underlying platform print routine.

Parameters

minLogLevel

minimum log level this logger outputs. Default: Level.VERBOSE.

filter

Lumberjack filter used to decide which logs are allowed. Default: DefaultLumberjackFilter.

tagTransformer

function called for every log with the runtime tag (may be null) and returning the final tag to use (or null to indicate no tag). The default is the identity function ({ it }) which leaves the runtime tag unchanged.

Notes and recommendations:

  • tagTransformer is invoked on every log call and therefore should be fast and side-effect free.

  • If you want to include a fixed prefix/tag, you can capture it from the surrounding scope: val logger = ConsoleLogger(tagTransformer = { tag -> if (tag != null) "FIXED-$tag" else "FIXED" })

  • The transformer may return null if no tag should be used.

Note: The logger intentionally places className before the "(file:line)" part so IDEs/logcat can make the filename:line clickable.

Constructors

Link copied to clipboard
constructor(minLogLevel: Level = Level.VERBOSE, filter: LumberjackFilter = DefaultLumberjackFilter, tagTransformer: (tag: String?) -> String? = { it })

Properties

Link copied to clipboard
open override val filter: LumberjackFilter
Link copied to clipboard
open override val minLogLevel: Level
Link copied to clipboard
val tagTransformer: (tag: String?) -> String?

Functions

Link copied to clipboard
open fun isEnabled(level: Level): Boolean
Link copied to clipboard
open override fun log(level: Level, tag: String?, time: Long, fileName: String, className: String, methodName: String, line: Int, msg: String?, throwable: Throwable?)