All Projects → MicroUtils → Kotlin Logging

MicroUtils / Kotlin Logging

Licence: apache-2.0
Lightweight logging framework for Kotlin. A convenient and performant logging library wrapping slf4j with Kotlin extensions

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kotlin Logging

Scala Logging
Convenient and performant logging library for Scala wrapping SLF4J.
Stars: ✭ 804 (-41.65%)
Mutual labels:  logging, jvm, slf4j
Scribe
The fastest logging library in the world. Built from scratch in Scala and programmatically configurable.
Stars: ✭ 304 (-77.94%)
Mutual labels:  logging, slf4j
Izumi
Productivity-oriented collection of lightweight fancy stuff for Scala toolchain
Stars: ✭ 423 (-69.3%)
Mutual labels:  logging, slf4j
liquibase-slf4j
Liquibase SLF4J Logger.
Stars: ✭ 42 (-96.95%)
Mutual labels:  slf4j, jvm
Testlogcollectors
A framework for capturing log statements during tests. Compatible with most popular logging frameworks. Works with JUnit and TestNG
Stars: ✭ 31 (-97.75%)
Mutual labels:  logging, slf4j
Timbre
Pure Clojure/Script logging library
Stars: ✭ 1,253 (-9.07%)
Mutual labels:  logging, slf4j
Kotlin Inline Logger
A logger facilitating lazily-evaluated log calls via Kotlin's inline classes & functions.
Stars: ✭ 77 (-94.41%)
Mutual labels:  jvm, slf4j
Zio Logging
Simple logging for ZIO apps, with correlation, context & pluggable backends out of the box.
Stars: ✭ 85 (-93.83%)
Mutual labels:  logging, slf4j
Logtrail
Kibana plugin to view, search & live tail log events
Stars: ✭ 1,343 (-2.54%)
Mutual labels:  logging
Jni By Examples
🎇Fun Java JNI By Examples - with CMake and C++ (or C, of course!) ‼️ Accepting PRs
Stars: ✭ 99 (-92.82%)
Mutual labels:  jvm
Lukyt
Small Java 8 JVM made in Lua
Stars: ✭ 95 (-93.11%)
Mutual labels:  jvm
React Native Device Log
A UI and service for handling/displaying dev log messages on devices
Stars: ✭ 96 (-93.03%)
Mutual labels:  logging
Debug
A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
Stars: ✭ 9,912 (+619.3%)
Mutual labels:  logging
Chromephp
class for logging PHP variables to Google Chrome console
Stars: ✭ 1,339 (-2.83%)
Mutual labels:  logging
Applicationinsights Dotnet Logging
.NET Logging adaptors
Stars: ✭ 100 (-92.74%)
Mutual labels:  logging
Logsip
A simple, concise, colorful logger for Go
Stars: ✭ 94 (-93.18%)
Mutual labels:  logging
Lumberjack
Chop and cut Angular logs like a professional lumberjack.
Stars: ✭ 93 (-93.25%)
Mutual labels:  logging
Rexlin600.github.io
系列博客、涵盖领域广、不定时更新、欢迎加入
Stars: ✭ 102 (-92.6%)
Mutual labels:  jvm
Foundatio
Pluggable foundation blocks for building distributed apps.
Stars: ✭ 1,365 (-0.94%)
Mutual labels:  logging
Punt
Punt is a tiny and lightweight daemon which helps ship logs to Elasticsearch.
Stars: ✭ 98 (-92.89%)
Mutual labels:  logging

kotlin-logging kotlin-logging Build Status Slack channel Download Maven Central Apache License V.2

Lightweight logging framework for Kotlin, written in Pure Kotlin.
A convenient and performant logging library wrapping slf4j with Kotlin extensions.

Call log methods, without checking whether the respective log level is enabled

logger.debug { "Some $expensive message!" }

Behind the scenes the expensive message do not get evaluated if debug is not enabled:

// This is what happens when you write the above ^^^
if (logger.isDebugEnabled) logger.debug("Some $expensive message!")

Define the logger, without explicitly specifiying the class name

// Place definition above class declaration to make field static
private val logger = KotlinLogging.logger {}

Behind the scenes val logger will be created in the class, with the class/file name:

// This is what happens when you write the above ^^^
val logger = LoggerFactory.getLogger("package.ClassName")

Log exceptions in a Kotlin-style

// exception as first parameter with message as lambda
logger.error(exception) { "a $fancy message about the $exception" }

Getting started

import mu.KotlinLogging
private val logger = KotlinLogging.logger {} 
class FooWithLogging {
    val message = "world"
    fun bar() {
        logger.debug { "hello $message" }
    }
}

An Android example project with kotlin-logging can be found in kotlin-logging-example-android.

Download

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. And an excellent detailed explanation in a-guide-to-logging-in-java.

In short, if you just want to log statements to stdout, it's possible to add the following dependency: org.slf4j:slf4j-simple:1.7.29.

Maven

<dependency>
  <groupId>io.github.microutils</groupId>
  <artifactId>kotlin-logging-jvm</artifactId>
  <version>2.0.6</version>
</dependency>

or

<dependency>
  <groupId>io.github.microutils</groupId>
  <artifactId>kotlin-logging</artifactId>
  <version>1.12.5</version>
</dependency>

See the full example in kotlin-logging-example-maven.

Gradle

implementation 'io.github.microutils:kotlin-logging-jvm:2.0.6'

or

implementation 'io.github.microutils:kotlin-logging:1.12.5'

Alternatively, download the JAR from github or bintray or maven-central.

Version 2.x vs 1.x

There are currently two supported branches: 1.x and 2.x.

The main incompatible change is in the artifact names. In version 1.x the jvm artifact is called kotlin-logging while in version 2.x it's called kotlin-logging-jvm to comply with the multiplatform schema. In addition, version 2.x supports only Kotlin >= 1.4.

Therefore, for jvm library owners it is still recommended to use 1.x, as for the rest of the use cases 2.x is recommended.

Multiplatform

An experimental common & JS & linux-x64 support is available.
More information is available on the wiki and issues #21 #45.

Snapshot builds

To get the latest non-stable version of kotlin logging use the following gradle configuration:

repositories {
	maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local' }
}

dependencies {
	implementation('io.github.microutils:kotlin-logging-jvm:2.0.0-SNAPSHOT')
}

Overview

After seeing many questions like Idiomatic way of logging in Kotlin and Best practices for loggers, 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:

  • No need to write the logger and class name or logger name boilerplate code.
  • A straight forward way to log messages with lazy-evaluated string using lambda expression {}.
  • All previous slf4j implementation can still be used.

Who is using it

And many more... (add your name above)

FAQ

  • Why not use plain slf4j? kotlin-logging has better native Kotlin support. It adds more functionality and enables less boilerplate code.
  • Is all slf4j implementation supported (Markers, params, etc')? Yes, kotlin-logging inherits Logger and all methods are supported.
  • Is location logging possible? Yes, location awareness was added in kotlin-logging 1.4.
  • 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.
  • Can I access the actual logger? Yes, via KLogger.underlyingLogger property.

Usage

  • See wiki for more examples.

It is possible to configure IntelliJ live templates. For file level logger configure the following:

  • Text template: private val logger = mu.KotlinLogging.logger {}.
  • Applicable in Kotlin: top-level.

Support

More links

Contributors

Any contribution is appreciated. See the contributors list in: https://github.com/MicroUtils/kotlin-logging/graphs/contributors

Contributing

Pull requests are welcome!
Show your ❤ with a ★

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].