-
Notifications
You must be signed in to change notification settings - Fork 562
Log with lazy messages and default tag parameters #546
Comments
@JakeWharton, what do you think? The proposed extension property above would create a new object on every invocation, which doesn't sound desirable. The lazy message is interesting but wouldn't you end up creating a lambda anyway instead of a String? |
The only added benefit of the lazy message in the implementation above would be if the computation for the object Log {
inline fun i(tag: String, msg: () -> String): Int {
return if (Log.isLoggable(tag, Log.INFO)) android.util.Log.i(tag, msg()) else 0
}
/* ... */
} |
With that you're going to cause confusion with two classes named I'm not sure logging extensions are all that useful in general since log calls tend to be guarded by I'd be open to lazy logging if we could hang static members on the real |
Alright then we'll just have to wait on https://youtrack.jetbrains.com/issue/KT-11968 |
I think it would be extremely useful to extend the
android.util.Log
API with the functionality of lazyString
messages and defaulttag
parameters like soThis could look like
This, of course, isn't ideal because we have to introduce an extension property. Even without the default tag parameter, however, due to https://youtrack.jetbrains.com/issue/KT-11968, it would have to be temporarily implemented in some other way besides a static extension function. For example,
This is also clearly not ideal so I'm not sure if this is something that we should wait on or can just implement in one of the two ways as above for now. I'm interested to hear other thoughts on this.
Note: This is similar to #289 but doesn't simplify the API excessively and also leverages the lazy lambdas correctly. On the other hand, this version doesn't get the benefit of inlining.
The text was updated successfully, but these errors were encountered: