LogcatStyleLogger

class LogcatStyleLogger(minPriority: LogPriority = LogPriority.DEBUG, time: Boolean = true, color: Boolean = true) : LogLogger

Logger that mimics the Android Logcat output style using println().

Depending on the configuration:

  • If time is true, logs are formatted as:

<date> <time> <pid> <priority> <logDomain>: <message>

Example: 2023-10-05 15:30:12.451 1234 D MyApp: A debug message

  • If time is false, logs are formatted as:

<priority>/<logDomain>(<pid>): <message>

Example: D/MyApp(1234): A debug message

If color is true, logs are prefixed with ANSI color codes based on the log priority.

Messages at LogPriority.ERROR are treated as fatal. After logging, an exception is raised to mimic g_log error behavior.

The time and color configurations are set when calling the install functions and cannot be changed afterward.

Installation

This logger can be installed conditionally:

Parameters

minPriority

The minimum log priority to log. Default is LogPriority.DEBUG.

time

Whether to include timestamps in the log output. Default is true.

color

Whether to include ANSI color codes in the log output. Default is true.

Constructors

Link copied to clipboard
constructor(minPriority: LogPriority = LogPriority.DEBUG, time: Boolean = true, color: Boolean = true)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun isLoggable(priority: LogPriority): Boolean

Returns true if the given priority is at least as severe as minPriority.

Link copied to clipboard
open override fun log(priority: LogPriority, logDomain: String, message: String)

Logs the given message at the specified priority and logDomain.