Skip to content

Commit

Permalink
Kpg/emoji writer (#185)
Browse files Browse the repository at this point in the history
* Emoji Xcode log

* Fix cinterop for Xcode 13

* Clean up Xcode logging

* bump api
  • Loading branch information
kpgalligan authored Oct 30, 2021
1 parent dea6444 commit a2ac854
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android.useAndroidX=true
org.gradle.jvmargs=-Xmx2g

GROUP=co.touchlab
VERSION_NAME=1.0.0-rc4
VERSION_NAME=1.0.0-SNAPSHOT
KOTLIN_VERSION=1.5.31

STATELY_VERSION=1.2.0-nmm
Expand Down
1 change: 1 addition & 0 deletions gradle/configure-crash-logger.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ kotlin {
].forEach { target ->
target.compilations.main.cinterops.create(project.name) {
includeDirs("$projectDir/src/include")
compilerOpts("-DNS_FORMAT_ARGUMENT(A)=")
if (printCInteropKotlin) {
extraOpts = listOf("-mode", "sourcecode")
}
Expand Down
3 changes: 2 additions & 1 deletion kermit-bugsnag/src/include/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ typedef NS_ENUM(NSUInteger, BSGBreadcrumbType) {
* a type.
*
* @param message The log message to leave.
* @param metadata Additional metadata included with the breadcrumb.
* @param metadata Diagnostic data relating to the breadcrumb.
* Values should be serializable to JSON with NSJSONSerialization.
* @param type A BSGBreadcrumbTypeValue denoting the type of breadcrumb.
*/
+ (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message
Expand Down
3 changes: 2 additions & 1 deletion kermit/api/android/kermit.api
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ public final class co/touchlab/kermit/BuildConfig {
public fun <init> ()V
}

public final class co/touchlab/kermit/CommonWriter : co/touchlab/kermit/LogWriter {
public class co/touchlab/kermit/CommonWriter : co/touchlab/kermit/LogWriter {
public fun <init> ()V
public fun formatMessage (Lco/touchlab/kermit/Severity;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)Ljava/lang/String;
public fun log (Lco/touchlab/kermit/Severity;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
}

Expand Down
3 changes: 2 additions & 1 deletion kermit/api/jvm/kermit.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public final class co/touchlab/kermit/CommonWriter : co/touchlab/kermit/LogWriter {
public class co/touchlab/kermit/CommonWriter : co/touchlab/kermit/LogWriter {
public fun <init> ()V
public fun formatMessage (Lco/touchlab/kermit/Severity;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)Ljava/lang/String;
public fun log (Lco/touchlab/kermit/Severity;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

package co.touchlab.kermit

class CommonWriter : LogWriter() {
open class CommonWriter : LogWriter() {
override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
println("$severity: ($tag) $message")
println(formatMessage(severity, message, tag, throwable))
throwable?.printStackTrace()
}

open fun formatMessage(severity: Severity, message: String, tag: String, throwable: Throwable?): String = "$severity: ($tag) $message"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021 Touchlab
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

package co.touchlab.kermit

import platform.Foundation.*

open class XcodeSeverityWriter : CommonWriter() {
private val df:NSDateFormatter = NSDateFormatter().apply {
dateFormat = "HH:mm:ss.SSS"
}

override fun formatMessage(severity: Severity, message: String, tag: String, throwable: Throwable?): String =
"${df.stringFromDate(NSDate.now)} ${emojiPrefix(severity)} $severity: ($tag) $message"

//If this looks familiar, yes, it came directly from Napier :) https://github.com/AAkira/Napier#darwinios-macos-watchos-tvosintelapple-silicon
open fun emojiPrefix(severity: Severity): String = when (severity) {
Severity.Verbose -> "⚪️"
Severity.Debug -> "🔵"
Severity.Info -> "🟢"
Severity.Warn -> "🟡"
Severity.Error -> "🔴"
Severity.Assert -> "🟤️"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

package co.touchlab.kermit

//Using CommonWriter instead of NSLogWriter because NSLog truncates stack trace prints: https://stackoverflow.com/a/39538500/227313
//Using EmojiSeverityWriter (base CommonWriter) instead of NSLogWriter because NSLog truncates stack trace prints: https://stackoverflow.com/a/39538500/227313
//Cutting off the stack trace makes local dev difficult when you get a Kotlin exception.
actual fun platformLogWriter(): LogWriter = CommonWriter()
actual fun platformLogWriter(): LogWriter = XcodeSeverityWriter()
2 changes: 1 addition & 1 deletion samples/sample/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions samples/sample/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/sample/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import shared
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

let kermit:Logger = Logger(config: StaticConfig(minSeverity: .verbose, logWriterList: [NSLogWriter(), OSLogWriter()]), tag: "iosTag")
let kermit:Logger = Logger.companion


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Expand Down
44 changes: 42 additions & 2 deletions samples/sample/KermitSampleIOS/KermitSampleIOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,49 @@ struct ContentView: View {
var body: some View {
VStack(spacing: 50){
Button(action: {
self.common.onClick()
self.common.onClickV()
}){
Text("Click Count").padding()
Text("Click Count V").padding()
.background(Color.blue)
.foregroundColor(.white)
.font(.title)
}
Button(action: {
self.common.onClickD()
}){
Text("Click Count D").padding()
.background(Color.blue)
.foregroundColor(.white)
.font(.title)
}
Button(action: {
self.common.onClickI()
}){
Text("Click Count I").padding()
.background(Color.blue)
.foregroundColor(.white)
.font(.title)
}
Button(action: {
self.common.onClickW()
}){
Text("Click Count W").padding()
.background(Color.blue)
.foregroundColor(.white)
.font(.title)
}
Button(action: {
self.common.onClickE()
}){
Text("Click Count E").padding()
.background(Color.blue)
.foregroundColor(.white)
.font(.title)
}
Button(action: {
self.common.onClickA()
}){
Text("Click Count A").padding()
.background(Color.blue)
.foregroundColor(.white)
.font(.title)
Expand Down
2 changes: 1 addition & 1 deletion samples/sample/KermitSampleIOS/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: eb18a5a396ff91b77d2f3b607dba9c4cf5f57893

COCOAPODS: 1.10.1
COCOAPODS: 1.11.2
2 changes: 2 additions & 0 deletions samples/sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {
repositories {
google()
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
}
extra.apply {
val parentKermit = java.util.Properties().apply { load(java.io.StringReader(File("${projectDir.path}/../../gradle.properties").readText())) }.get("VERSION_NAME") as String
Expand All @@ -27,6 +28,7 @@ allprojects {
repositories {
mavenLocal()
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
google()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,35 @@ import co.touchlab.kermit.Logger

class SampleCommon(private val logger: Logger) {
private var count = 0
fun onClick() {
fun onClickI() {
count++
logger.i { "Common click count: $count" }
}

fun onClickW() {
count++
logger.w { "Common click count: $count" }
}

fun onClickE() {
count++
logger.e { "Common click count: $count" }
}

fun onClickA() {
count++
logger.a { "Common click count: $count" }
}

fun onClickD() {
count++
logger.d { "Common click count: $count" }
}
fun onClickV() {
count++
logger.v { "Common click count: $count" }
}

fun logException(){
logger.w(throwable = Exception("Handled")) { "Common click count: $count" }
}
Expand Down

0 comments on commit a2ac854

Please sign in to comment.