# Kotlin Logs Kotlin.jvm.internal.ClassReference as Log Prefix in Server Logs

**URL:** <https://discuss.kotlinlang.org/t/kotlin-logs-kotlin-jvm-internal-classreference-as-log-prefix-in-server-logs/7844>\
**Category:** Support\
**Created:** [May 17, 2018, 8:21pm UTC](https://discuss.kotlinlang.org/t/kotlin-logs-kotlin-jvm-internal-classreference-as-log-prefix-in-server-logs/7844 "2018-05-17T20:21:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehal10988](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mehal10988](https://discuss.kotlinlang.org/u/mehal10988)\
**Post date:** [May 17, 2018, 8:21pm UTC](https://discuss.kotlinlang.org/t/kotlin-logs-kotlin-jvm-internal-classreference-as-log-prefix-in-server-logs/7844/1 "2018-05-17T20:21:49Z")

</div>

Hi,

I am using Apache Logging library (org.apache.logging.log4j) to log various things as part of my server stack.  
Using code block similar to below generates following type of Log statements in the server logs… Why is the log prefix NOT that of Kotlin class through which instance of Log4j is created? This happens only when I log statements from within lambda functions like `also`.

```auto
class KotlinClass {

    companion object {
        val LOG = org.apache.logging.log4j.LogManager.getLogger(KotlinClass::class)
    }

...
...

fun doSomething() {

    LOG.info("Inside doSomething() method")
    val isValid = getValid().also {
                                            LOG.info("Obtained valid result $it")
                                       }
}

```

Server generated LOG:

```auto
...
TIMESTAMP.. com.abcd.efgh.KotlinClass: Inside doSomething() method
TIMESTAMP.. Kotlin.jvm.internal.ClassReference: Obtained valid result false
...

```

Any idea on what can be done to log ‘Class Name’ as prefix irrespective of where the log is being generated?

---

<div class="post-metadata">

**Author:** ![SackCastellon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sackcastellon/32/4553_2.png) [@SackCastellon](https://discuss.kotlinlang.org/u/SackCastellon)\
**Post date:** [May 17, 2018, 8:56pm UTC](https://discuss.kotlinlang.org/t/kotlin-logs-kotlin-jvm-internal-classreference-as-log-prefix-in-server-logs/7844/2 "2018-05-17T20:56:36Z")

</div>

I am not really sure why that happens, but this is what I use:

Filename: **HelloWorld.kt**

```auto
import java.util.*

private val LOG: org.apache.logging.log4j.Logger = org.apache.logging.log4j.LogManager.getLogger()

class Test {
    fun doSomething() {
        LOG.info("Inside doSomething() method")
        Random().nextInt().also { LOG.info("Generated random integer: $it") }
    }
}

fun main(args: Array<String>) {
    LOG.info("Hello world!")
    Test().doSomething()
}

```

And the output is this:

```auto
2018-05-17 22:47:40,820 I [main] [HelloWorldKt] Hello world!
2018-05-17 22:47:40,823 I [main] [HelloWorldKt] Inside doSomething() method
2018-05-17 22:47:40,825 I [main] [HelloWorldKt] Generated random integer: 405623303

```

This way, instead of logging the calss name it will log the filename.

---

<div class="post-metadata">

**Author:** ![Beholder](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beholder/32/2078_2.png) [@Beholder](https://discuss.kotlinlang.org/u/Beholder)\
**Post date:** [May 18, 2018, 5:11pm UTC](https://discuss.kotlinlang.org/t/kotlin-logs-kotlin-jvm-internal-classreference-as-log-prefix-in-server-logs/7844/3 "2018-05-18T17:11:31Z")

</div>

The type of expression `KotlinClass::class` is `KClass`, not `Class`. So method you called was `LogManager.getLogger(Object)`, which calls `.getClass()` on it argument. You should use expresion `KotlinClass::class.java`.
