Code Monkey home page Code Monkey logo

Comments (4)

ewoelfel avatar ewoelfel commented on June 2, 2024 1

you can do the following:

private val logger = KotlinLogging.logger {}
class MyClass {
  init {
    logger.info{ "Example" }
  }
}

or if you like to use a companion object:

class MyClass {
  init {
    logger.info{ "Example" }
  }
  companion object {
    private val logger = KotlinLogging.logger {}
  }
}

from kotlin-logging.

github-actions avatar github-actions commented on June 2, 2024

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

from kotlin-logging.

alex-shinn avatar alex-shinn commented on June 2, 2024

This begs the question why was the raw string usage deprecated?

The lambda is an optimization only if the log is ultimately not omitted (and the log string contains interpolation). Otherwise it's actually an (admittedly small) pessimization, since you need the extra bytecode and memory usage for the lambda, and extra CPU for invocation.

In practice the log level is fixed in production, and we would never want to suppress info or higher logs anyway. So in our codebase we tend to use lambdas for expensive debug logs and strings for everything else. Forcing everything to be a lambda is just wasteful.

from kotlin-logging.

oshai avatar oshai commented on June 2, 2024

This begs the question why was the raw string usage deprecated?

The main motivation was to make the api clearer.
With the old api methods parameters matrix became too complex (raw string also requires parameters, throwable, markers etc'). That's why most frameworks are moving toward fluent api. I tried to make the api "kotlin native" and clearer for users. I agreed it's opinionated compared to previous version.

from kotlin-logging.

Related Issues (20)

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.