Giter Site home page Giter Site logo

Comments (8)

bensandee avatar bensandee commented on June 11, 2024

I would argue that these are not idiomatic for Kotlin and that they would introduce extra ambiguity when it comes to code completion. Including them would expose methods that are inherently less safe as well, as referenced in the readme section about lint checks.

The only reason I'd use the old syntax would be for compatibility while migrating code but I would prefer to do that one module at a time any ways.

from timberkt.

bj0 avatar bj0 commented on June 11, 2024

It's hard to argue it's not idomatic for Kotlin when that's exaclty what Anko does: https://github.com/Kotlin/anko/wiki/Anko-Commons-%E2%80%93-Logging

Not sure about safety, I was just thinking more for people who are use to using systems like Anko, it would make it cognitively easier to use. I currently just create my own.

from timberkt.

bensandee avatar bensandee commented on June 11, 2024

Personally, I don't use or like Anko. It's popular but that doesn't make it idiomatic Kotlin. But whatever, I don't care either way. Maybe patches welcome, eh?

from timberkt.

bj0 avatar bj0 commented on June 11, 2024

I also don't use Anko anymore, but I only meant that since there's no specific word on it in https://kotlinlang.org/docs/reference/idioms.html, than official kotlin/jetbrains libraries like Anko are going to be most commonly referenced as what's 'idiomatic'. I can look into creating a patch with my extensions if there's interest beyond just me.

from timberkt.

bensandee avatar bensandee commented on June 11, 2024

I think that how Kotlin handles check() and require() are great examples of how logging should be handled idiomatically. I fail to see how parametric substitution methods offer anything of value beyond the inline string substitutions and like I said, it's easier to make mistakes (wrong number of arguments, etc) and catching those requires lint checks, etc.

That said, I feel like the whole point is moot. One fatal flaw for this lib at the moment is that logging messages are fully realized and rendered any time a Tree is plant()ed. In my reading of the code, it does not matter if the log message will actually be logged or not, based on the underlying priorities. This is substantially different behavior from Timber.

(updated w/clarifications)

from timberkt.

bj0 avatar bj0 commented on June 11, 2024

I didn't have parametric substitution in mind, only basic no-arg strings like d("this method called"). For anything else I would use a lambda.

I didn't notice the log check before, good point. And looking at Timber, since isLoggable is per-tree, you couldn't really support passing in lambdas that deep without rewriting timber in Kotlin.

from timberkt.

bensandee avatar bensandee commented on June 11, 2024

Even with that addition it is easy to make a mistake if you're not paying attention. If your log message inadvertently has inline string subs (a situation that should be very common and expected in Kotlin), the method invocation that takes a string will cause the log message to be built regardless. So even if underlying issue discussed earlier is fixed, this is still a potential programming issue -- particularly for people who don't have a firm grasp on lambdas vs strings.

You could add these as a companion functions without changes to this lib:

inline fun TimberKt.d(message: String) = Timber.d(message)

from timberkt.

ajalt avatar ajalt commented on June 11, 2024

Thanks for the detailed discussion! I would prefer not to add another overload for all the functions, especially when the new version is error prone.

@tbsandee Version 1.1.0 didn't call the log lambda unless the message was actually logged. However, since Timber doesn't expose isLoggable, the implementation used non-inline lambdas. If you're ok with that and need the precise behavior, that version works fine.

from timberkt.

Related Issues (9)

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.