{"id":26071323,"url":"https://github.com/MicroUtils/kotlin-logging","last_synced_at":"2025-03-09T00:03:04.847Z","repository":{"id":9606215,"uuid":"62350009","full_name":"oshai/kotlin-logging","owner":"oshai","description":"Lightweight Multiplatform logging framework for Kotlin. A convenient and performant logging facade.","archived":false,"fork":false,"pushed_at":"2024-10-28T05:59:32.000Z","size":947,"stargazers_count":2642,"open_issues_count":18,"forks_count":113,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-10-29T15:01:24.064Z","etag":null,"topics":["android","jvm","kotlin","logging","multiplatform","slf4j"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oshai.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog-old.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"oshai","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-07-01T00:13:49.000Z","updated_at":"2024-10-29T07:16:28.000Z","dependencies_parsed_at":"2023-02-17T20:45:57.307Z","dependency_job_id":"de4b9b34-a7d3-43a4-a3eb-dd20b3125241","html_url":"https://github.com/oshai/kotlin-logging","commit_stats":{"total_commits":748,"total_committers":51,"mean_commits":"14.666666666666666","dds":"0.31417112299465244","last_synced_commit":"4452814117585b98a0e6f9644d02f4c5224934cb"},"previous_names":["microutils/kotlin-logging","microutils/kotlin.logging"],"tags_count":100,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oshai%2Fkotlin-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oshai%2Fkotlin-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oshai%2Fkotlin-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oshai%2Fkotlin-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oshai","download_url":"https://codeload.github.com/oshai/kotlin-logging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242623568,"owners_count":20159704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","jvm","kotlin","logging","multiplatform","slf4j"],"created_at":"2025-03-09T00:01:24.426Z","updated_at":"2025-03-09T00:03:04.783Z","avatar_url":"https://github.com/oshai.png","language":"Kotlin","funding_links":["https://github.com/sponsors/oshai"],"categories":["Libraries","必备开发库"],"sub_categories":["Logging","Kotlin 基础"],"readme":"# [kotlin-logging](https://github.com/oshai/kotlin-logging) [![CI](https://github.com/oshai/kotlin-logging/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/oshai/kotlin-logging/actions/workflows/ci.yml) [![Slack channel](https://img.shields.io/badge/Chat-Slack-blue.svg)](https://kotlinlang.slack.com/messages/kotlin-logging/) [![Maven Central](https://img.shields.io/maven-central/v/io.github.oshai/kotlin-logging.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.github.oshai%22) [![Apache License V.2](https://img.shields.io/badge/license-Apache%20V.2-blue.svg)](https://github.com/oshai/kotlin-logging/blob/master/LICENSE)\n\nLightweight Multiplatform logging framework for Kotlin, written in \n[![Pure Kotlin](https://img.shields.io/badge/100%25-kotlin-blue.svg)](https://kotlinlang.org/).  \nA convenient and performant logging facade.  \n\n#### Call log methods, without checking whether the respective log level is enabled\n```Kotlin\nlogger.debug { \"Some $expensive message!\" }\n```\n\nBehind the scenes the expensive message do not get evaluated if debug is not enabled:\n```Kotlin\n// This is what happens when you write the above ^^^\nif (logger.isDebugEnabled) logger.debug(\"Some $expensive message!\")\n```\n\n#### Define the logger, without explicitly specifying the class name\n```Kotlin\n// Place definition above class declaration to make field static\nprivate val logger = KotlinLogging.logger {}\n```\n\nBehind the scenes `val logger` will be created in the class, with the class/file name:\n```Kotlin\n// This is what happens when you write the above ^^^\nval logger = LoggerFactory.getLogger(\"package.ClassName\")\n```\n\n#### Log exceptions in a Kotlin-style\n```Kotlin\n// exception as first parameter with message as lambda\nlogger.error(exception) { \"a $fancy message about the $exception\" }\n```\n\n#### Fluent logging in a Kotlin-style\n```kotlin\nlogger.atWarn {\n    message    = \"foo $bar\"\n    cause      = exception\n    payload    = buildMap(capacity = 3) {\n        put(\"foo\", 1)\n        put(\"bar\", \"x\")\n        put(\"obj\", Pair(2, 3))\n    }\n}\n```\n\n## Getting started\n \n```Kotlin\nimport io.github.oshai.kotlinlogging.KotlinLogging\n\nprivate val logger = KotlinLogging.logger {} \n\nclass FooWithLogging {\n    val message = \"world\"\n    fun bar() {\n        logger.debug { \"hello $message\" }\n    }\n}\n```\n\n## Download\n\n**Important note:** kotlin-logging depends on slf4j-api (in the JVM artifact). In runtime, it is also required to depend on a logging implementation. More details in [how-to-configure-slf4j](http://saltnlight5.blogspot.co.il/2013/08/how-to-configure-slf4j-with-different.html). And an excellent detailed explanation in [a-guide-to-logging-in-java](https://www.marcobehler.com/guides/a-guide-to-logging-in-java).  \nIn version 5 users should also provide slf4j-api dependency.\n\nIn short, if you just want to log statements to stdout, it's possible to add the following dependency: `org.slf4j:slf4j-simple:2.0.3`.\n\n### Maven\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.oshai\u003c/groupId\u003e\n  \u003cartifactId\u003ekotlin-logging-jvm\u003c/artifactId\u003e\n  \u003cversion\u003e7.0.3\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nSee the full example in [kotlin-logging-example-maven](https://github.com/oshai/kotlin-logging-example-maven).  \n\n### Gradle\n```Groovy\nimplementation 'io.github.oshai:kotlin-logging-jvm:7.0.3'\n```\n\n\nAlternatively, download the JAR from [github](https://github.com/oshai/kotlin-logging/releases/latest)  or [maven-central](https://repo1.maven.org/maven2/io/github/oshai/).\n\n### Multiplatform\n\nAn experimental multiplatform support is available.  \nMore information is available on the [wiki](https://github.com/oshai/kotlin-logging/wiki/Multiplatform-support) and issues [#21](https://github.com/oshai/kotlin-logging/issues/21) [#45](https://github.com/oshai/kotlin-logging/issues/45).\n\n## Overview\n\nAfter seeing many questions like [Idiomatic way of logging in Kotlin](http://stackoverflow.com/questions/34416869/idiomatic-way-of-logging-in-kotlin) and [Best practices for loggers](https://discuss.kotlinlang.org/t/best-practices-for-loggers/226/15), it seems like there should be a standard for logging and obtaining a logger in Kotlin. kotlin-logging provides a wrapper for slf4j-api to be used by Kotlin classes with the following advantages:\n  - No need to write the logger and class name or logger name boilerplate code.\n  - A straight forward way to log messages with lazy-evaluated string using lambda expression `{}`.\n  - All previous slf4j implementation can still be used.\n\n\n## Version 5 vs. previous versions\n\nVersion 5 is not backward compatible with previous versions (v.3, v.2, v.1). Group id (in maven) and packages names changed.\nIt is possible to use both version 5 and previous versions side-by-side so some of the code from the old version\nand some new. It is also possible to have libs using old version and use the new version (and vice-versa).  \nIn that sense it's a completely new dependency.\n\nMain changes are:\n- Maven group id changed from `io.github.microutils` -\u003e `io.github.oshai`.\n- Root package change from `mu` -\u003e `io.github.oshai.kotlinlogging`.\n- Slf4j dependency is not provided anymore (users have to provide it). It means that \u003e= 5.x can work with both slf4j 1 or 2.\n- There are changes to multiplatform class hierarchy that might break compatibility.\n\nMore details in issue [#264](https://github.com/oshai/kotlin-logging/issues/264), \nand in the [change log](https://github.com/oshai/kotlin-logging/blob/master/ChangeLog.md)\n\n\n\n## Who is using it\n\n- https://www.jetbrains.com/youtrack/ (https://www.jetbrains.com/help/youtrack/standalone/Third-Party-Software-Used-by-YouTrack.html)\n- https://github.com/DiUS/pact-jvm\n- https://github.com/AsynkronIT/protoactor-kotlin\n- https://github.com/square/misk\n- https://github.com/openrndr/openrndr\n- https://github.com/JetBrains/xodus\n\nAnd many more... (add your name above)\n\n## FAQ\n\n- Why not use plain slf4j? kotlin-logging has better native Kotlin support. It adds more functionality and enables less boilerplate code.\n- Is all slf4j implementation supported (Markers, params, etc')? Yes.\n- Is location logging possible? Yes, location awareness was added in kotlin-logging 1.4.\n- When I do `logger.debug`, my IntelliJ IDEA run console doesn't show any output. Do you know how I could set the console logger to debug or trace levels? Is this an IDE setting, or can it be set in the call to KLogging()? Setting log level is done per implementation. kotlin-logging and slf4j are just facades for the underlying logging lib (log4j, logback etc') more details [here](http://stackoverflow.com/questions/43146977/how-to-configure-kotlin-logging-logger).\n- Can I access the actual logger? In platforms available yes, via `DelegatingKLogger.underlyingLogger` property.\n\n## Usage\n\n- See [wiki](https://github.com/oshai/kotlin-logging/wiki) for more examples.\n\nIt is possible to configure IntelliJ live templates. For file level logger configure the following:\n- Text template: `private val logger = io.github.oshai.kotlinlogging.KotlinLogging.logger {}`.\n- Applicable in `Kotlin: top-level`.\n\n## Support\n\n- Open an issue here: https://github.com/oshai/kotlin-logging/issues\n- Ask a question in StackOverflow with [kotlin-logging tag](http://stackoverflow.com/tags/kotlin-logging/info).\n- Chat on Slack channel: https://kotlinlang.slack.com/messages/kotlin-logging\n- Chat on Telegram channel: https://t.me/klogging\n\n## More links\n\n- https://medium.com/@OhadShai/logging-in-kotlin-95a4e76388f2\n- [kotlin-logging vs AnkoLogger for Android](https://medium.com/@OhadShai/logging-in-android-ankologger-vs-kotlin-logging-bb693671442a)\n- [How kotlin-logging was published](https://medium.com/@OhadShai/no-forks-one-star-now-what-how-i-published-my-open-source-projects-8a5b5ae35d2c#.e3ygj6uf3)\n- [Kotlin Logging Without the Fuss](https://realjenius.com/2017/08/31/logging-in-kotlin/)\n- [DropWizard + Kotlin = Project Kronslott](https://medium.com/@davideriksson_91895/dropwizard-kotlin-project-kronslott-e2aa51b277b8)\n- [Logging in Kotlin – the right approach](https://amarszalek.net/blog/2018/05/13/logging-in-kotlin-right-approach/)\n- https://bednarek.wroclaw.pl/log4j-in-kotlin/\n- https://jaxenter.com/kotlin-logging-168814.html\n\n## Contributing\n\nAny contribution is appreciated.  \nSee the contributors list in: https://github.com/oshai/kotlin-logging/graphs/contributors\n\nPull requests are welcome! See instructions in https://github.com/oshai/kotlin-logging/blob/master/CONTRIBUTING.md.  \n\n[Show your ❤ with a ★](https://github.com/oshai/kotlin-logging/stargazers)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMicroUtils%2Fkotlin-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMicroUtils%2Fkotlin-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMicroUtils%2Fkotlin-logging/lists"}