

Kermit KMP Logging 1.0
source link: https://touchlab.co/kermit-kmp-logging-1-0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Kermit KMP Logging 1.0
Today we’re announcing the stable release of our logging library Kermit
If you’ve been following me, I’ve given a few talks on Kotlin KMP library development. In my previous talks I gave some suggestions on what kinds of libraries the community needs. I went out of my way to say avoid building logging libraries. Even way back in 2019, there were already a few options for KMP, so I assumed that topic was handled.

Don’t build logging libraries
After doing some digging, though, nothing really felt like it was done the way we wanted. Also, in early 2020, due in part due to circumstances we’re all aware of, we had a few more hands available than planned. We had wanted everybody on the team to get a chance to work on a KMP library, and logging libraries are, if nothing else, conceptually straightforward. After some general architecture chats, the team dove in and made a dev version of Kermit.
The plan was to try it out, get some feedback, then make a 1.0 and tell everybody!
Then we got super busy.
The good news is we got some extra time to think about the library design, and a lot more feedback than you’d think for something we never quite announced.
With that feedback, plus more lessons learned shipping KMP code in the meantime, we sat down and made a plan for Kermit 1.0.
Kermit 1.0
Kermit has a simple API, is easy to extend, and is focused on performance. Getting started is very easy, but Kermit provides more sophisticated configuration as you move beyond dev into releasing your applications.
Rather than a single long post that I’ll never finish, we’ll wrap this up with basic setup, then go deep on a few other topics in future posts. The list is subject to change, but look for posts on basic setup and usage, production setup, crash reporting integration, and a deep dive on the performance considerations that went into the design.
Note: Kotlin 1.6.0 publishing issues
To clarify some confusion around releases, we originally published 1.0.0 for Kotlin 1.5.31, then this post got delayed a bit. When Kotlin 1.6.0 came out, we ran into some Kotlin/Native stuff that needed fixing, but ultimately pushed Kermit 1.0.2 with Kotlin 1.6.0. However, it turns out Kotlin 1.6.0 has Android publishing issues, so please use Kermit 1.0.0 until Kotlin 1.6.10 releases, which should be in a couple weeks.
Getting Started
In your Kotlin Gradle config, add the Kermit dependency in `commonMain`.
commonMain { dependencies { implementation("co.touchlab:kermit:1.0.0") } }
Without any other configuration, you can use the global Logger with default log writers per platform. For Android, it writes to android.util.Log, iOS logs are written with println, and JS goes to console.
For iOS we replicated a good idea from Napier. Color coding the iOS logs. Format is slightly different, but same concept.

iOS Color Coded Output
To write logs with the global logger, just do this:
Logger.i { "Hello" }
The log calls are lambdas, which will allow us to avoid creating strings if they’re not needed, but you can also call “regular” methods with a string.
To log an exception:
catch(ex:Exception){ Logger.e(ex) { "Something happened" } }
To change tags, do this:
val l = Logger.withTag("DifferentTag") l.i { "New logger, new tag" }
That’s it for today. Again, keep an eye out for other posts about Kermit. Please share feedback, star the Github repo if you like it.
Work at Touchlab!
We’re hiring! If you want to help define the future of Kotlin, and like living a bit on the edge technically speaking, please reach out!
Recommend
-
40
-
29
预计阅读时间:15 分钟 KMP 算法(Knuth-Morris-Pratt 算法)是一个著名的字符串匹配算法,效率很高,但是确实有点复杂。 很多读者抱怨 KMP 算法无法理解,这很正常,想到大学教材...
-
24
KMP算法(摘自百度百科):KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt提出的,因此人们称它为克努特-莫里斯-普拉特操作(简称KMP算法)。KMP算法的核心是利用匹配失败后的信息,尽量减少模式串与主串的匹配次...
-
24
前言 字符串的匹配是编写程序的时候经常遇到的一个问题,也是计算机处理的基础问题之一。最简单的方法是循环字符串,一位一位地进行匹配,也可以使用正则表达式。今天本文讨论用状态机的模型如...
-
8
什么是KMP算法: KMP是三位大牛:D.E.Knuth、J.H.Morris和V.R.Pratt同时发现的。其中第一位就是《计算机程序设计艺术》的作者!! KMP算法要解决的问题就是在字符串(也叫主串)中的模式(pattern)定位问题。说...
-
12
动态规划之KMP字符匹配算法 👆让天下没有难刷的算法!若 GitBook 访问太慢,可尝试
-
32
Kermit Software Source Code Archive - Web Access Frank da Cruz Most recent update:Â Â Sat Sep 5 13:44:16 2020 This is a newer version of the
-
10
链表、栈与队列、kmp; 数组模拟单链表: 用的最多的是邻接表--就是多个单链表: 作用:存储树与图 需要明确相关定义: 为什么需要使用数组模拟链表 比使用结构体 或者类来说 速度...
-
10
Kermit - Misconceptions and Controversies This page updated 2 August 2021: FTP links changed to HTTP. "Kermit is slow". ...
-
1
Fun with Kermit and ZMODEM over SSH Frederic Cambus April 25, 2023 [...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK