https://kotlinlang.org logo
#ktor
Title
# ktor
a

Alex Cruise

08/12/2022, 5:04 PM
Is there a way to add a suffix/tag to logs based on which module/plugin/etc. is doing the logging? Right now it’s always
Application
a

Aleksei Tirman [JB]

08/12/2022, 5:43 PM
Could you please explain what log messages are you talking about (on a client or a server)?
a

Alex Cruise

08/12/2022, 5:44 PM
In a server, I’d like to see which module/plugin logged the line
Ideally without needing to add the tag manually to every slf4j call 🙂
I guess something like constructing a child logger from the one I got from the environment
f

FunkyMuse

08/12/2022, 5:59 PM
You can tag your path
a

Alex Cruise

08/12/2022, 6:02 PM
slf4j “marker” feature?
a

Aleksei Tirman [JB]

08/12/2022, 6:37 PM
There is a brittle solution to implement your own
org.slf4j.Logger
where you can retrieve a calling class from the stack trace and log its name or its source file name. That will work on JVM only.
Copy code
ApplicationEngineEnvironmentReloading.kt: Autoreload is disabled because the development mode is off.
BaseApplicationEngine.kt: Application started in 0.095 seconds.
CallLogging.kt: Application started: io.ktor.server.application.Application@5b3f61ff
BaseApplicationEngine.kt: Responding at <http://0.0.0.0:3333>
server.kt: ewqe
CallLogging.kt: 200 OK: GET - /
10 Views