https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-logging
  • c

    christophsturm

    06/14/2017, 12:19 PM
    does kotlint-logging support mocking the logger?
    o
    • 2
    • 11
  • c

    codeslubber

    06/14/2017, 3:18 PM
    I’m using kotlin-logging, finding that it seems pretty random but sometime you have to add a newline or your next log message ends up stuck to the end of the prior one…
    o
    • 2
    • 15
  • d

    deviant

    08/09/2018, 1:23 PM
    hi guys! is it possible to configure colorful logging in java app based on log level? like it done in android logcat
    🌈 2
    b
    • 2
    • 3
  • k

    Konstantin Petrukhnov

    09/11/2018, 4:27 PM
    does kotlin-logging work on ios?
    o
    • 2
    • 2
  • c

    cmgurba

    10/18/2018, 2:29 PM
    I'm doing some json formatting of our logs using logback config. We use kotlin-logging in our app. Does anybody have an example / doc on how to capture logging output to assert against in a unit test from kotlin-logging?
    o
    • 2
    • 3
  • s

    Shan

    02/25/2019, 1:07 AM
    Hey all. I have a project that has a dependency that has a bunch of log statements using Kotlin logger. When I run my project, I can see the depdency's DEBUG and INFO level logs, but not TRACE level logs (which I need to see). I have tried slf4j
    SimpleLogger
    with configuration
    System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE")
    but could still not see trace level logs. I then switched to
    slf4j-log4j12
    to rule out
    SimpleLogger
    issues, with config file
    log4j.rootLogger=TRACE, STDOUT
    log4j.logger.deng=TRACE
    log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
    log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
    log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
    and still no trace logs show. Any ideas what I'm doing wrong?
    o
    • 2
    • 1
  • n

    Nikky

    02/27/2019, 4:36 PM
    and thats what confuses me.. is there some sort of seperate debug only configuration that i have not set or so..
    o
    • 2
    • 3
  • n

    Nikky

    02/27/2019, 11:05 PM
    logback.xml
    s
    • 2
    • 1
  • n

    Nikky

    03/01/2019, 1:52 PM
    in evaluatted scripts i get this output:
    14:49:03.787 [main] .(null:7)   INFO  - >>>> executing step two
    instead of null i would expect scriptFile.kts
    o
    • 2
    • 5
  • z

    zjuhasz

    04/04/2019, 6:26 PM
    Is there a recommended way to use a logger from a public inline function? I could do
    @PublishedApi internal val logger = KotlinLogging.logger {}
    but that would get confusing with my other loggers. Should I just give it a unique name or is there a better way?
    o
    • 2
    • 5
  • u

    Uzi Landsmann

    05/21/2019, 4:15 AM
    I’m asking because in my logback conf I specify using debug but I can’t see any debug logs when the application runs. What else do I need to do?
    o
    • 2
    • 1
  • c

    corneil

    08/08/2019, 2:39 PM
    Native or JVM?
    v
    • 2
    • 4
  • n

    Nikky

    10/12/2019, 7:47 PM
    so for my multiplatform app (jfx, js and ktor server on jvm) i want to add better logging i guess kotlin-logging seems to be ready to try but i have some questions.. like why are the
    msg: () -> Any?
    not
    inline
    , that would make some stuff where i call suspending stuff possible i guess that would break compatibility with the slf4j stuff ?
    o
    • 2
    • 1
  • n

    Nikky

    10/12/2019, 7:48 PM
    also can i use kotlin-logging to also read the log messages that have been sent ? i want to add a logger panel to my client if possible
    o
    • 2
    • 1
  • n

    Nikky

    10/12/2019, 9:38 PM
    seems like the code on github is.. outdated ? there is 1.7.6 on maven but in the buildscript is https://github.com/MicroUtils/kotlin-logging/blob/master/build.gradle.kts#L15
    o
    • 2
    • 1
  • k

    Konstantin Petrukhnov

    02/10/2020, 11:23 AM
    How does defining kotlin-logging works with libraries? E.g. I'm building lib, that need logging. I want that application will provide instance of KLogger to my lib. If application don't provide it, then some default KLogger should be used. Question is, hot to initialize it, so I don't need to put logger in every class?
    o
    • 2
    • 2
  • c

    corneil

    02/10/2020, 1:41 PM
    If you declare a global
    val logger = KotlinLogging.logger {}
    you should be able to use it anywhere.
    m
    • 2
    • 8
  • c

    corneil

    02/11/2020, 1:01 PM
    kotlin-logging is a MPP library that uses SLF4J on JVM, SLF4J is a facade to whatever implementation you choose. So I wouldn't be worried about 3 libraries. Does logback-android provide what you need. You can choose to use it with or without kotlin-logging as SLF4J is automatically included with logback. I believe kotlin-logging offer advantages that make logging code efficient and as unintrusive as possible.
    m
    • 2
    • 6
  • n

    napperley

    06/21/2020, 1:24 AM
    I have created a PR ( https://github.com/MicroUtils/kotlin-logging/pull/119 ) for adding support for the Kotlin Native linuxX64 target. Would welcome some feedback, and would like to get some guidance from a Kotlin Native team member on a major design question.
    • 1
    • 2
  • b

    bsimmons

    07/06/2020, 6:15 PM
    Hey all, is it possible to use just the KLogger interface/facade in a MPP library and let it be manually implemented on each platform? (I have an iOS target that I can't build for because kotlin-logging doesn't support it.)
    o
    • 2
    • 16
  • d

    Dennis Schröder

    08/26/2020, 7:05 AM
    Hey, is there a way to intercept all the logs to e.g. send them to an Elasticsearch instance etc.?
    m
    • 2
    • 1
  • v

    vitaliy

    08/27/2020, 9:28 AM
    Hi everybody, I have a small question about performance of
    <http://logger.info|logger.info>("blah $foo $bar")
    vs
    <http://logger.info|logger.info> { "blah $foo $bar" }
    . I suppose: 1. in the first case the string template is always constructed 2. in the second one only when the log level is set to make it visible. But there is extra lambda, etc. Is it something I should worry about under a rather intensive load (backend) or it’s not worth optimizing?
    o
    • 2
    • 1
  • o

    oshai

    09/15/2020, 8:28 PM
    2.0.0 is almost ready with kotlin 1.4 support and more platforms and needs feedback Breaking change is a change in the artifact coordinates from
    kotlin-logging
    to
    kotlin-logging-jvm
    In order to try it:
    repositories {
    	maven { url '<https://oss.jfrog.org/artifactory/oss-snapshot-local>' }
    }
    
    dependencies {
    	compile('io.github.microutils:kotlin-logging-jvm:2.0.0-SNAPSHOT')
    }
    • 1
    • 1
  • t

    TwoClocks

    10/27/2020, 1:46 AM
    basic question : I want all my log messages to be pre-pending w/ a specific string, and that string is setup when the logger is created by appending to the end of the existing string. so you kinda create a tree of "child" loggers. not sure if that makes sense. How would i do that using kotlin-logging?
    o
    • 2
    • 16
  • n

    Nikky

    11/01/2020, 12:33 PM
    Why are log functions not inline btw? If they were i would not need weird workarounds for suspending functions..
    o
    • 2
    • 3
  • a

    Alec Muffett

    11/06/2020, 2:57 PM
    Hi All! I am trying to find out if I have found a bug, or else have just misunderstood something. I'm learning Kotlin and kotlin-logging; I have some code which looks like:
    import ...
    private val logger: KLogger = KotlinLogging.logger {}
    internal class Engine(private val di: DI) {
        fun mainMethod(args: Array<String>) { // called from "real" main()
            System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG")
            logger.trace("trace")
            logger.debug("debug")
            <http://logger.info|logger.info>("info")
            logger.warn("warning")
            logger.error("error")
    ...and when it runs, it is (sensibly) printing:
    [main] DEBUG psm.Engine - debug
    [main] INFO psm.Engine - info
    [main] WARN psm.Engine - warning
    [main] ERROR psm.Engine - error
    HOWEVER: as soon as I declare another
    logger: KLogger = KotlinLogging.logger {}
    in another classfile in the same package, the behaviour *changes*; more in comments:
    o
    • 2
    • 7
  • t

    TwoClocks

    11/10/2020, 8:29 AM
    is there anyway to hide/disable the ability to get the default logger? I have a framework where I only want to loggers created by a factory in the framework.
    o
    • 2
    • 4
  • n

    Nikky

    11/12/2020, 11:04 AM
    how can i retrieve MDC from a CoroutineContext in a exception handler ? the code looks like so currently
    private val exceptionHandler = CoroutineExceptionHandler { context, e -> GlobalScope.launch(MDCContext() + context) {
    can i somehow do
    context.getCopyOfContextMap()
    ?
    o
    • 2
    • 7
  • f

    Francois Stiennon

    12/21/2020, 7:41 PM
    Hi everybody, thought I'd share this small library to write logs to OpenTracing spans https://github.com/fstien/kotlin-logging-opentracing-decorator
    🎉 2
    o
    • 2
    • 1
  • c

    christophsturm

    01/19/2021, 1:25 PM
    what do you guys think of creating a kotlin-logging package that depends on log4j2 and has a useful default config?
    o
    • 2
    • 6
Powered by Linen
Title
c

christophsturm

01/19/2021, 1:25 PM
what do you guys think of creating a kotlin-logging package that depends on log4j2 and has a useful default config?
o

oshai

01/24/2021, 10:04 PM
not sure what you mean. can you explain?
c

christophsturm

01/24/2021, 10:07 PM
in my build file i have this lines corresponding to logging:
implementation("io.github.microutils:kotlin-logging:2.0.4")
    implementation("org.apache.logging.log4j:log4j-core:$log4j2Version")
    implementation("org.apache.logging.log4j:log4j-api:$log4j2Version")
    implementation("org.apache.logging.log4j:log4j-jul:$log4j2Version")
    implementation("org.apache.logging.log4j:log4j-slf4j18-impl:$log4j2Version")
its pretty hard to get right.
i think it would be great to have an opinionated gradle dependency that is sufficient to get decent logging without many pitfalls
o

oshai

01/25/2021, 4:22 AM
ok, but you still need the xml. Maybe an example (in a blogpost or wiki) is enough?
c

christophsturm

02/20/2021, 1:01 PM
You could do without the xml and configure via Kotlin code. And even offer an Kotlin api that makes configuration easy. But I never got configuration via Kotlin code working.
View count: 23