bbaldino
01/30/2020, 8:00 PMinline fun <reified T : Any> T.createChildLogger(
parentLogger: Logger,
childContext: Map<String, String> = emptyMap()
): Logger =
parentLogger.createChildLogger(getClassForLogging(T::class.java).name, childContext)
Which is used to abstract out the logic for obtaining the 'name' of the logger using the caller's class, but I'm finding I can't invoke it in-place when calling a parent constructor, like so:
class Foo(parentLogger: Logger) : Parent(createChildLogger(parentLogger))
I assume this is because the receiver function can't be applied here? Is there a workaround for something like this? (either in the definition of createChildLogger
, or how it would be invoked by the child class?bbaldino
01/30/2020, 8:01 PMcreateChildLogger
as an inline function (not a receiver) and obtain the calling class that way, but I don't know if there's any good way to dynamically 'detect' if it's running from within a class or notbbaldino
01/30/2020, 8:02 PMbbaldino
01/30/2020, 8:06 PMthis
to a parent (meaning it was at least somewhat accessible, and therefore could get the class), but I just tested that out and it seemed like it isn't accessible at all:bbaldino
01/30/2020, 8:06 PMinterface Handler
open class Parent(val handler: Handler)
class Child : Handler, Parent(this)
complains about "this" is not defined in this context
bbaldino
01/30/2020, 8:10 PMoperator invoke
trick on the companion object to work around it, but wondering if there's a better way