Giter Site home page Giter Site logo

kflogger's Introduction

KFlogger: Experimental KMP port of Flogger

NOTE: This is an experimental project and is not meant to be used in production environments.

Supported Platforms

Target Platform Target preset
Kotlin/JVM
  • jvm
iOS
  • iosArm64
  • iosX64
  • iosSimulatorArm64

Install

// build.gradle.kts

implementation("com.giancarlobuenaflor:kflogger:<version>")

Usage

import com.giancarlobuenaflor.kflogger.KFluentLogger

class LoggingClass {
  val logger = KFluentLogger.forEnclosingClass()

  fun loggingMethod() {
    logger.atWarning().log("my message: %s", "Hello World")
  }
}

Current state as of commit e724eeba1fd440b20bf8e865a1d735a0dd238ec0

Common functionality

  • logging simple messages without arguments at all log levels -> log.atWarning().log("my message") or log.atFine().log("my message")
  • logging messages with printf format -> log.atWarning("my message: $s", "test") although this is only limited to `%s, %d, %i, %f% due to lack of implementation on the iOS side.
  • avoid work at log site with lazy -> log.atWarning("complex work: $s", KLazyArgs.lazy { "result" })

Implementation approach

We use actual typealias very extensively to make sure we can keep the original Flogger Java code. This has some weird caveats, for example Java protected does not equal Kotlin protected or Kotlin companion functions cannot be typealiased to static functions on Java. The workaround here is to ignore those errors and make sure compilation works through tests.

JVM Flogger

The core functionality will work as usual on JVM.

Most of the code has been directly transferred from Flogger. Changes to the Flogger API to accomodate KMP are very minimal and are the following:

Currently only the api module is available in KMP but adding the other ones should not be an issue since the api module is already incorporated into KMP.

iOS

The iOS implementation has a lot of gaps and many TODOs.

It only contains the core implementations necessary to make the common functionality work.

  • OSLog is used as default logging backend.
  • The printf format is done manually inside SimpleLoggerBackend. This is less than ideal and should be properly implemented via PrintfMessageParser and the BaseMessageFormatter and other relevant classes.
  • findLoggingClass has been implemented with NSThread.callStackSymbols. This implementation assumes that the logging class is within the common Kotlin code. So it won't work for native Obj-c or Swift classes.

Testing

JVM Flogger contains the original test cases.

The common code is tested via Kruth. The approach here is to take the JVM Flogger tests 1:1 and apply them to Kruth to make sure functionality is consistent across all platforms.

In addition to ensure the actual typealias work for all defined common code we test compilation of all KMP classes to make sure we don't run into any runtime errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.