Questions tagged [kotlin-logging]

Lightweight logging framework for Kotlin. A wrapper for slf4j with Kotlin extensions.

See more details here: https://github.com/MicroUtils/kotlin-logging

13 questions
214
votes
18 answers

Idiomatic way of logging in Kotlin

Kotlin doesn't have the same notion of static fields as used in Java. In Java, the generally accepted way of doing logging is: public class Foo { private static final Logger LOG = LoggerFactory.getLogger(Foo.class); } Question is what is the…
mchlstckl
  • 3,390
  • 2
  • 21
  • 21
19
votes
4 answers

how to configure kotlin-logging logger

For logging purposes in my Kotlin project I am using kotlin-logging which is really nice to use however I am missing a very central point: How can I configure the log level of the logger? Per default it is set to info and I would like to set it to…
Jakob Abfalter
  • 4,980
  • 17
  • 54
  • 94
6
votes
1 answer

Kotlin logger - log to a file

class LogToFile(context: Context) { companion object: KLogging() val formatter = SimpleFormatter() // val logger = LoggerFactory.getLogger("MyLog") **WITH THIS LINE...** val logger = Logger.getLogger("MyLog") //this…
Sophie M
  • 351
  • 5
  • 14
2
votes
2 answers

How do I get kotlin-logging (MicroUtils) to print to subclass name instead of abstract class name?

I'm using kotlin-logging (https://github.com/MicroUtils/kotlin-logging), I want my logger to print to subclass name instead of abstract class name. Example I have these class // in A.kt file: import mu.KotlinLogging private val logger =…
Timothy
  • 55
  • 1
  • 5
2
votes
1 answer

How to ALSO send kotlin-logging logs (sl4j-simple?) to my own back-end

I have a working solution using kotlin-logging and slf4j-simple. It happily prints to the console. Question: I'd like to also send log lines to my own function so I can save them to my alternate destination (that isn't one of the built-in ones like…
Benjamin H
  • 5,164
  • 6
  • 34
  • 42
1
vote
0 answers

Put KotlinLogging Logger call in another file and retain name

With KotlinLogger and SLF4J, I want to do something like // In Log.kt val logger = KotlinLogging.logger {} // In Main.kt after importing logger fun main() { val loggerMain = KotlinLogging.logger {} loggerMain.info("Hello world") // Main: Hello…
Danny
  • 244
  • 3
  • 14
1
vote
1 answer

How to wrap an existing slf4j logger into a kotlin logger?

Given an existing slf4j logger, I would like to wrap it into an kotlin-logging logger. The classes / methods to do that already exists in the library but are internal, so I can't call them: mu.internal.KLoggerFactory.wrapJLogger() Is there another…
Dieter
  • 301
  • 4
  • 11
1
vote
2 answers

What is an idiomatic Kotlin way to aquire a Logger?

I'm looking to replace private static final Logger log = Logger.getLogger(MyClass.class); with something that is a little less verbose and more idiomatic then class MyClass { companion object { val log =…
atok
  • 5,880
  • 3
  • 33
  • 62
0
votes
1 answer

Kotlin: Delegate override function how to make work with lambda and function parens

I am trying to override the error() method of kotlin-logging. The following code is close to what I want, but I don’t understand a few things (I’m new to Kotlin). Example code: import mu.KLogger import mu.KotlinLogging open class BgrLogging( …
mhulse
  • 4,062
  • 6
  • 28
  • 35
0
votes
0 answers

Can't choose Kotlin-Logging logger name

Kotlin-logging is a thin convenience wrapper around SLF4J. Its docs indicate I can choose an arbitrary logger name. But when I do, the logger stops working :-( Here are the log declaration and log format that do work. logback.xml file:…
devdanke
  • 1,309
  • 15
  • 27
0
votes
0 answers

How to set "TAG" when using kotlin-logging in android project?

I am using Kotlin-Logging in my Android App. How do I set the TAG for my log statements? Currently in my view-model I have something like: class MyViewModel(private val dictionary: Dictionary) : ViewModel() { companion object:…
hba
  • 7,406
  • 10
  • 63
  • 105
0
votes
0 answers

Gradle, error: module not found: kotlin.logging

These are my dependencies in build.gradle.kts: implementation("io.github.microutils:kotlin-logging:1.7.8") implementation("org.slf4j:slf4j-api:1.7.29") Then in module-info.java: requires kotlin.logging; All the rest works fine with the…
elect
  • 6,765
  • 10
  • 53
  • 119
0
votes
0 answers

Does anko logger library log message in debug build or signed build also

I am trying to use anko commons library for logging debug message on logcat. I want to display logging message in debug build not in signed build. I know I can remove logging in signed builds using Proguard also. I want to know if anko library…
N Sharma
  • 33,489
  • 95
  • 256
  • 444