GithubHelp home page GithubHelp logo

cxwudi / kotlin-jvm-inline-logging Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 68 KB

A fully inlined SLF4J for Kotlin/JVM 1.5+ ๐Ÿ˜Ž

License: Do What The F*ck You Want To Public License

Kotlin 100.00%
kotlin kotlin-jvm kotlin-library jvm slf4j logger inline

kotlin-jvm-inline-logging's Introduction

Kotlin/JVM Inline Logging

badge

Powered by SLF4J, fully inlined, and say goodbye to lambda object creation ๐Ÿ˜ฒ

Prerequisites

  • Java 8+
  • Kotlin 1.5.0+

Features

  • Fully inlined SLF4J logger
  • lazily create log message without creating lambda object (because everything is inlined ๐Ÿ˜‹)
  • only showing lazy logging methods on your IDE (e.g. showing logger.info {} on your auto-complete hint instead of logger.info())

How to import

Check JitPack to see how to import

How to use

Simply add

private val logger = KInlineLogging.logger()

to anywhere you want and enjoy logging ๐Ÿ˜

For example:

private val logger = KInlineLogging.logger() // an instance of KInlineLogger, which is a value class of SLF4J Logger

class MainApp {
  fun start() {
    logger.info { "an info msg" }
    val exception = SomeException()
    logger.debug(exception) { "a debug msg with exception $exception" }
  }
}

Under the hook, this should be compiled as:

private val logger: Logger = LoggerFactory.getLogger(
  KInlineLoggerNameResolver.fixName(MethodHandles.lookup().lookupClass())
) // A SLF4J Logger, not the KInlineLogger ๐Ÿ˜ฏ

class MainApp {
  fun start() {
    if (logger.isInfoEnabled()){
      logger.info("an info msg") // no lambda object created ๐Ÿ˜Š
    }
    val exception = SomeException()
    if (logger.isDebugEnabled()){
      // notice that this string creation will not happen if the debug level is not enabled
      logger.debug("a debug msg with exception $exception", exception) 
    } 
  }
}

Q: Can you support multi-platform?

A: Sorry, I am not supporting it, but you can just grab the only two source files in this library and modify it to suit your needs.

kotlin-jvm-inline-logging's People

Contributors

cxwudi avatar

Watchers

 avatar

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.