· 2 min read Posted by Kevin Schildhorn

Kermit 2.0.5 updates OSLogWriter and adds file logging

The 2.0.5 update for Kermit is out now and features various updates to OSLogWriter, as well as the ability to log to a file.
https://unsplash.com/photos/file-cabinet-Q9y3LRuuxmg
Credit: https://unsplash.com/photos/file-cabinet-Q9y3LRuuxmg

Kermit 2.0.5 has just been released! With the help of the community this new version includes updates to OSLogWriter, upgrades to kotlin 2.0.10, and a new kermit-io module for writing logs to a file.

OSLogWriter

First off some updates to OSLogWriter for better OSLog support in iOS. OSLogWriter now takes in three additional optional parameters: subsystem, category, and publicLogging.

OSLogWriter(
    messageStringFormatter: MessageStringFormatter = DefaultFormatter, 
    subsystem: String = "", 
    category: String = "",
    publicLogging: Boolean = false,
)

Subsystem and category may seem familiar to developers familiar with OSLog. These two strings are passed directly into OSLog internally so that your logs can be categorized, filtered, and grouped in iOS.

PublicLogging is a boolean that enforces logs sent to iOS are completely public. By default OSLog redacts contents of dynamic strings for privacy concerns, however Kermit uses dynamic strings to log which can cause obfuscated logs in certain conditions. The publicLogging boolean enforces that logs are public, therefore preventing any redaction from OSLog.

PublicLogging by default is set to false. This is because we don’t want to change the default implementation silently and make logs thought to be private suddenly public. There may be existing users of Kermit that have sensitive data in their logs, and we don’t want to change their logs that they expect are private to suddenly be public.

Kermit-IO

A new module named Kermit-IO has been added to the library. This module adds the RollingFileLogWriter, which supports logging to files using kotlinx-io. As the name suggests this log writer supports automatic roll-overs and deletion of older logs.

open class RollingFileLogWriter(
  private val config: RollingFileLogWriterConfig,
  private val messageStringFormatter: MessageStringFormatter = DefaultFormatter,
  private val clock: Clock = Clock.System,
  private val fileSystem: FileSystem = SystemFileSystem,
) : LogWriter()

It takes in a configuration including details about the file and rollover details.

data class RollingFileLogWriterConfig(
  val logFileName: String,
  val logFilePath: Path,
  val rollOnSize: Long = 10 * 1024 * 1024, // 10MB
  val maxLogFiles: Int = 5,
  val logTag: Boolean = true,
  val prependTimestamp: Boolean = true,
)

For more details on how to implement this RollingFileLogWriter check out the sample in the repo. The file name and path are passed into the SampleMobile class.

Contributors

A huge thank you to the contributors of these changes!