https://kotlinlang.org logo
Title
f

frogger

02/15/2018, 1:13 PM
for configuring my logger in classes i use
MyClass::class.java.simpleName
. I want to setup a logger for my kotlin file (no classes inside), can I get the FQN of the kotlin file somehow? e.g.
com.example.stuff.UtilitiesKt
?
e

Egor Trutenko

02/15/2018, 1:16 PM
Try
MyClass::class.java.getCanonicalName()
Remember, by calling
::class.java
you get access to all the methods defined in
Class
from Java library
f

frogger

02/15/2018, 1:19 PM
Thanks for the hint. Any idea about getting the FQN of the kotlin file?
s

spand

02/15/2018, 1:30 PM
Define a toplevel method and use:
tlm.javaMethod!!.declaringClass.name
f

frogger

02/15/2018, 1:33 PM
perfect thanks. From you answer I assume there is no "kotlin native" i.e. JVM independent way to access it, right?
s

spand

02/15/2018, 1:36 PM
Not that I know of. I think at one point they wanted to introduce File and Package concepts in reflection but havent seen any of that yet.
f

frogger

02/15/2018, 1:39 PM
👍