Coder Social home page Coder Social logo

Comments (6)

oshai avatar oshai commented on May 25, 2024

I think it should work (unless the function is inline) Can you provide a code sample that it is not working for reproduction?

from kotlin-logging.

kkocel avatar kkocel commented on May 25, 2024

I just wonder where to put initialization block. Inside each extension function that will log anything?
In some sort of companion object? Named object?

Logging itself works - but I want to get relevant name from the context where it's created.

from kotlin-logging.

oshai avatar oshai commented on May 25, 2024

Are you talking about the name of the logger? If so then you probably can access it if its public and declared in hierarchy.

from kotlin-logging.

oshai avatar oshai commented on May 25, 2024

@kkocel can I close the issue?

from kotlin-logging.

kkocel avatar kkocel commented on May 25, 2024

Hi, I think I wasn't clear in previous posts. Now I'll try to be more specific and provide examples :)

Let's say I have following extension function inside file MyDomainObjectMapper.kt:

  fun String.toMyClass(): MyClass {

    logger.debug { "Mapping class type [$this] to my class" }
    //...
  }

// inside same file there couple of other extensions functions which are doing some logging as well

I use logger here and my question is - where to initialize such logger in a way that it will be able to obtain name of the class. And how to initialize such logger once so I won't need to to do it in every extension function.

from kotlin-logging.

oshai avatar oshai commented on May 25, 2024

I would keep all loggers in a map in the file, class as key logger as value. With lazy init and limit on size. However, I don't know your actual use case but usually logger should reflect the file the nessage was printed and not the class it is extending. Hope that helps.

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.