Lightweight logging library for Kotlin/Multiplatform. Supports Android, iOS, JavaScript and plain JVM environments.

Overview

Log4K

License Maven Central Build Status badge-android badge-native badge-js badge-jvm Kotlin Version

Lightweight logging library for Kotlin/Multiplatform. Supports Android, iOS, JavaScript and plain JVM environments.

Download

Artifacts are published to Maven Central:

repositories {
    mavenCentral()
}

dependencies {
    implementation("de.peilicke.sascha:log4k:1.0.1")
}

Usage

Logging messages is straightforward, the Log object provides the usual functions you'd expect:

Log.verbose("FYI")
Log.debug("Debugging ${foo.bar}")
Log.info("Nice to know")
Log.warn("Warning about $stuff ...")
Log.error("Oops!")
Log.assert("Something went wrong!", throwable)

The log output includes the function name and line and pretty-prints exceptions on all supported platforms:

I/Application.onCreate: Log4K rocks!

Configuration (Android example)

To only output messages with log-level info and above, you can configure the console logger in your Application class:

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Log.loggers.add(ConsoleLogger().apply {
            if (!BuildConfig.DEBUG) {
                minimumLogLevel = Log.Level.Info
            }
        })
    }
}

Custom logger (Android Crashlytics example)

The library provides a cross-platform ConsoleLogger by default. Custom loggers can easily be added. For instance, to send only ERROR and ASSERT messages to Crashlytics in production builds, you could do the following:

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Log.loggers += when {
            BuildConfig.DEBUG -> ConsoleLogger()
            else -> CrashlyticsLogger()
        }
    }

    private class CrashlyticsLogger : Logger() {
        override fun print(level: Log.Level, tag: String, message: String?, throwable: Throwable?) {
            val priority = when (level) {
                Log.Level.Verbose -> VERBOSE
                Log.Level.Debug -> DEBUG
                Log.Level.Info -> INFO
                Log.Level.Warning -> WARN
                Log.Level.Error -> ERROR
                Log.Level.Assert -> ASSERT
            }
            if (priority >= ERROR) {
                FirebaseCrashlytics.getInstance().log("$priority $tag $message")
                throwable?.let { FirebaseCrashlytics.getInstance().recordException(it) }
            }
        }
    }
}

Users

License

Copyright 2019 Sascha Peilicke

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Any plans to support lazy evaluation of log messages?

    Any plans to support lazy evaluation of log messages?

    Sometimes log messages use string interpolation that call "expensive" functions to compose the final string. Commonly, log frameworks offer an API that takes the message as a lambda in that case (like Log.info { "Did ${compute()} things." }), so string interpolation only happens if the respective log level is active. Is something like that also planned for Log4k?

    opened by sschuberth 2
  • Add SLF4J integration as a new library

    Add SLF4J integration as a new library

    Forwards log requests to SLF4J, which in turn allows to use Logback as a backend. This provides rich appenders and output configuration via logback.xml files. It can replace the default ConsoleLogger on JVM and Android platforms. To keep things simple, the JavaScript and Apple platform implementation log to the console.

    documentation enhancement 
    opened by saschpe 0
  • Android: Update to API 32

    Android: Update to API 32

    And use Android Gradle Plugin 7.2.1 as well as build-tools 33.0.0. See upstream release notes:

    • https://developer.android.com/studio/releases/platforms#12
    • https://developer.android.com/studio/releases/gradle-plugin#7-2-0
    • https://developer.android.com/studio/releases/build-tools
    enhancement 
    opened by saschpe 0
  • Increase Java compatibility

    Increase Java compatibility

    By adding JvmOverloads and @JvmStatic annotations to generate static methods on the 'Log' object. This makes it easier to call any log function though JNI.

    Add @JvmField to Log.loggers to keep the API simple to use in Java.

    enhancement 
    opened by saschpe 0
  • Create FileLogger

    Create FileLogger

    Requirements

    • Should avoid dependencies on ktor-io or kotlinx-datetime
    • Available for JVM, Android and iOS at least
      • Not sure what file could mean in a browser context
    • Should allow to rotate logs
      • Daily
      • Every X lines logged

    Usage Draft

    Log.loggers += FileLogger(logDir = "my/logs", rotation = Rotate.After(lines = 4096))
    
    enhancement 
    opened by saschpe 0
Releases(release/1.2.3)
  • release/1.2.3(Oct 12, 2022)

  • release/1.2.2(Jul 12, 2022)

  • release/1.2.1(Jul 12, 2022)

    What's Changed

    • New library log4k-slf4j:
      • SLF4JLogger: Forwards log statements to SLF4J, which in turn allows to use [Logback])(https://logback.qos.ch) as a backend.

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.2.0...release/1.2.1

    Source code(tar.gz)
    Source code(zip)
  • release/1.2.0(Jul 12, 2022)

  • release/1.1.3(Jul 12, 2022)

    What's Changed

    • Add method Log.isDebugEnabled identical to SLF4J's LOG.isDebugEnabled().
    • Dependency update:

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.1.2...release/1.1.3

    Source code(tar.gz)
    Source code(zip)
  • release/1.1.2(Jun 27, 2022)

    What's Changed

    • Android: Update to API 32 by @saschpe in https://github.com/saschpe/Log4K/pull/21

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.1.1...release/1.1.2

    Source code(tar.gz)
    Source code(zip)
  • release/1.1.1(Jun 27, 2022)

    What's Changed

    • Increased Java compatibility by @saschpe in https://github.com/saschpe/Log4K/pull/20
    • Support Java 17

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.1.0...release/1.1.1

    Source code(tar.gz)
    Source code(zip)
  • release/1.1.0(Jun 10, 2022)

    What's Changed

    • Add log methods that take a message-providing lambda

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.0.3...release/1.1.0

    Source code(tar.gz)
    Source code(zip)
  • release/1.0.3(Jun 10, 2022)

    What's Changed

    • Various fixes and improvements by @saschpe in https://github.com/saschpe/Log4K/pull/16
    • Kotlin: Update to 1.7.0
    • Update 3rd-party dependencies.

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.0.2...release/1.0.3

    Source code(tar.gz)
    Source code(zip)
  • release/1.0.2(Jun 9, 2022)

    What's Changed

    • Updates by @saschpe in https://github.com/saschpe/Log4K/pull/12
    • Maven central by @saschpe in https://github.com/saschpe/Log4K/pull/13
    • Updates and Maven Central publishing by @saschpe in https://github.com/saschpe/Log4K/pull/14
    • Gitlab Actions: Implement Sonatype publishing by @saschpe in https://github.com/saschpe/Log4K/pull/15

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.0.0...release/1.0.2

    Source code(tar.gz)
    Source code(zip)
  • release/1.0.1(Mar 10, 2022)

    What's Changed

    • Updates by @saschpe in https://github.com/saschpe/Log4K/pull/12
    • Maven central by @saschpe in https://github.com/saschpe/Log4K/pull/13

    Full Changelog: https://github.com/saschpe/Log4K/compare/release/1.0.0...release/1.0.1

    Source code(tar.gz)
    Source code(zip)
  • release/1.0.0(Mar 10, 2022)

    What's Changed

    • Add publish job by @saschpe in https://github.com/saschpe/Log4K/pull/1
    • Add 'spotless' job to 'main' Github Actions workflow by @saschpe in https://github.com/saschpe/Log4K/pull/2
    • Proper README.md by @saschpe in https://github.com/saschpe/Log4K/pull/3
    • Use macOS CI environment by @saschpe in https://github.com/saschpe/Log4K/pull/4
    • Install GnuPG via brew by @saschpe in https://github.com/saschpe/Log4K/pull/5
    • Update version in README.md by @saschpe in https://github.com/saschpe/Log4K/pull/6
    • Things by @saschpe in https://github.com/saschpe/Log4K/pull/7
    • Create gradle-wrapper-validation.yml by @saschpe in https://github.com/saschpe/Log4K/pull/9
    • Add custom logging example to README.md by @saschpe in https://github.com/saschpe/Log4K/pull/8
    • Gradle stuff by @saschpe in https://github.com/saschpe/Log4K/pull/10
    • Updates by @saschpe in https://github.com/saschpe/Log4K/pull/11

    Full Changelog: https://github.com/saschpe/Log4K/commits/release/1.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Sascha Peilicke
IT Consultant ‧ Cloud | Mobile | Startup
Sascha Peilicke
Depenject - a lightweight, minimalistic dependency injection library for Kotlin/JVM.

depenject depenject is a lightweight, minimalistic dependency injection library for Kotlin/JVM. Our goal is similar to flavor's to simplify the usage

Patrick 1 Mar 22, 2022
A simple, lightweight, non-bloated redis client for kotlin and other JVM languages

rekt is a lightweight, non-bloated redis client, primarily written for the kotlin programming language, while also supporting other JVM-based languages, such as Java, Scala, and obviously way more.

Patrick 8 Nov 2, 2022
This Kotlin Multiplatform library is for accessing the TMDB API to get movie and TV show content. Using for Android, iOS, and JS projects.

Website | Forum | Documentation | TMDb 3 API Get movie and TV show content from TMDb in a fast and simple way. TMDb API This library gives access to T

Moviebase 37 Dec 29, 2022
Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on.

JavierSC Kotlin template Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on. Features Easy to p

Javier Segovia Córdoba 2 Dec 14, 2022
A counter down timer for android which supports both dark and light mode and Persian text and digit.

FlipTimerView A counter down timer for android which supports both dark and light mode and Persian text and digit. English Perisan Getting started Ste

Arezoo Nazer 7 Jul 17, 2022
MaxonBank is a Kotlin + Spring Boot + Axon Framework application that supports opening, depositing to, and withdrawing from accounts.

MaxonBank MaxonBank is a Kotlin + Spring Boot + Axon Framework application that supports opening, depositing to, and withdrawing from accounts. The ap

Max 1 Dec 30, 2021
Utility library dedicated for functional & non-functional codebases to simplify modelling of success and failure responses for the JVM languages 🔀

Expressible Utility library, part of the panda-lang SDK, dedicated for functional codebases that require enhanced response handling. Express yourself

Panda 28 Nov 14, 2022
Kotlin SDK for Jellyfin supporting Android and the JVM.

Jellyfin Kotlin SDK Part of the Jellyfin Project The Jellyfin Kotlin SDK is a library implementing the Jellyfin API to easily access servers. It is cu

Jellyfin 60 Dec 18, 2022
JVM Open Asset Import Library (Assimp)

assimp JVM porting of Assimp This port is being written trying to stick as much as possible close to the C version in order to: minimize maintenance t

null 83 Oct 30, 2022
Collection of JVM library logic that the Sirloin software development team is currently using

Collection of JVM library logic that the Sirloin software development team is currently using

Sirloin Dev 4 May 10, 2022
Kotlin jvm + android packages for bdk-ffi

bdk-kotlin This project builds .jar and .aar packages for the jvm and android platforms that provide Kotlin language bindings for the bdk library. The

Bitcoin Dev Kit 14 Nov 15, 2022
An implementation of MediatR on JVM for Spring using Kotlin coroutines

Kpring MediatR In this project, an attempt has been made to implement the mediator pattern on the JVM with simplicity using Kotlin with native corouti

Mahdi Bohloul 4 Aug 6, 2022
Asynchronous Spring Initializr API wrapper for Kotlin/JVM

initializr-kt Asynchronous Spring Initializr API wrapper for Kotlin/JVM. This library provides the simplest DSL for initializing Spring Boot projects

Mikhail Titov 2 May 8, 2022
StarkNet SDK for JVM languages (java, kotlin, scala)

☕ starknet jvm ☕ StarkNet SDK for JVM languages: Java Kotlin Scala Clojure Groovy Table of contents Documentation Example usages Making synchronous re

Software Mansion 29 Dec 15, 2022
FlowExt is a Kotlin Multiplatform library, that provides many operators and extensions to Kotlin Coroutines Flow

FlowExt | Kotlinx Coroutines Flow Extensions | Kotlinx Coroutines Flow Extensions. Extensions to the Kotlin Flow library | kotlin-flow-extensions | Coroutines Flow Extensions | Kotlin Flow extensions | kotlin flow extensions | Flow extensions

Petrus Nguyễn Thái Học 151 Jan 1, 2023
A lightweight Kotlin library which converts images to PixelArt in Android.

PixelArtImageView PixelArtImageView is a lightweight library used to convert standalone images into pixel art. The view extends ImageView behaviour an

Josh Owen 2 May 15, 2022
Kotools Assert is a lightweight assertions library for Kotlin

Kotools Assert is a lightweight assertions library for Kotlin

Kotools 1 Nov 3, 2022
Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Mockative 121 Dec 26, 2022
A simple, lightweight and powerful field validation library for Android.

Convalida Convalida - (Italian for "validation") Convalida is a simple, lightweight and powerful field validation library for Android. Documentation G

Wellington Costa 203 Nov 18, 2022