simple Kotlin logging: colorized logs for Kotlin on the JVM

Overview

sklog - simple Kotlin logging

Kotlin (JVM) logging library for printing colorized text to the console, with an easy upgrade path to the popular kotlin-logging library

Rationale

Logging is a necessary part of most projects, but setting it up can be a chore.

Java has several popular logging frameworks, as well as the built-in java.util.logging, but all come with their own issues.

For Kotlin, the kotlin-logging library has become relatively popular, but it's not a standalone logger. Instead, it acts as a wrapper around SLF4J, which is itself a logging "facade" (i.e., frontend), meaning that it requires a separate backend/implementation to work.

As a result, even if all you want to do is print log output to the console (System.err), you'll need to pull in three separate dependencies: kotlin-logging, SLF4J, and SLF4J's Simple implementation. That can be a lot, especially for smaller projects with relatively simple logging needs.

It can also be difficult to figure out how to configure these libraries, for example if you want to change the log level so that you actually see debug messages.

This library exists to make it easy to start logging, without worrying about dependencies and complex configuration.

Features

  • No dependencies, other than the Kotlin language and the Java standard library
  • Messages are printed to System.err
  • Output includes timestamp and the name of the class where the logger was declared
    • Possible to set custom logger names
  • Output colorized based on log level
    • But this can be disabled
  • Log level can be customized
  • No other customizations are available in this library
  • But it's really easy to upgrade to a more full-featured solution, the kotlin-logging library! (see below)

Example & usage

screenshot showing sample output of sklog

This screenshot was generated by the following program:

import sklog.KotlinLogging
import sklog.LogLevel

private val logger = KotlinLogging.logger {}

fun main() {
    // The default log level is DEBUG,
    // but it can be set to TRACE globally or on a per-logger basis
    logger.logLevel = LogLevel.TRACE

    println("Welcome! This is a test run of sklog, the simple kotlin logging library.")
    println("Each of the following lines is logger output.")

    logger.trace { "Trace" }
    logger.debug { "Debug" }
    logger.info { "Info" }
    logger.warning("Warning")
    logger.error("Error")
}

Using this library

This library is made available via JitPack. Here's how you can add it to your project:

Gradle (build.gradle.kts)

repositories {
    maven {
        url = uri("https://jitpack.io")
    }
}

dependencies {
    implementation("com.github.nmalkin:sklog:0.0.1")
}

Gradle (build.gradle)

repositories {
    maven {
        url 'https://jitpack.io'
    }
}

dependencies {
    implementation 'com.github.nmalkin:sklog:0.0.1'
}

Maven

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependency>
  <groupId>com.github.nmalkin</groupId>
  <artifactId>sklog</artifactId>
  <version>0.0.1</version>
</dependency>

Upgrade path

If you start using this library and realize you need more features, upgrading to the kotlin-logging library should be very easy! This library's API was based on kotlin-logging and designed to be compatible. In particular:

  • Loggers are declared the same way
    private val logger = KotlinLogging.logger {}
  • Messages can be logged as lambdas (so they don't get evaluated if the log level is disabled)
    logger.debug { "Some $expensive message!" }

Because of this, upgrading to kotlin-logging might be as simple as swapping our your imports:

< import sklog.KotlinLogging
---
> import mu.KotlinLogging
You might also like...
Jambo is an open source remote logging library
Jambo is an open source remote logging library

Jambo Jambo is an open source remote logging library. For those who would like to see their logs remotely on their android device Jambo is the library

✔️ Simple, pretty and powerful logger for android
✔️ Simple, pretty and powerful logger for android

Logger Simple, pretty and powerful logger for android Setup Download implementation 'com.orhanobut:logger:2.2.0' Initialize Logger.addLogAdapter(new A

Simple application to log your mood through the day and explain feature flags.

Mood Logger App (Android version) This Repo This repository contains code for building a very basic application to log your mood through the days. The

Napier is a logger library for Kotlin Multiplatform.
Napier is a logger library for Kotlin Multiplatform.

Napier is a logger library for Kotlin Multiplatform. It supports for the android, ios, jvm, js. Logs written in common module are displayed on logger

Kotlin Multi Platform Logger, for android an ios : Logcat & print

Multiplatform Preferences Use a single object : Logger in your kotlin shared projects to display logs Note you can also use it in your real code on An

Yakl - Yet Another Kotlin Logger

YAKL Yet Another Kotlin Logger. Motivation Current jvm loggers have some disadva

Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Trail Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platfor

Kotlin multi-platform logging library with structured logging and coroutines support
Kotlin multi-platform logging library with structured logging and coroutines support

Klogging Klogging is a pure-Kotlin logging library that aims to be flexible and easy to use. It uses Kotlin idioms for creating loggers and sending lo

Create a simple and more understandable Android logs.
Create a simple and more understandable Android logs.

DebugLog Create a simple and more understandable Android logs. #Why? android.util.Log is the most usable library of the Android. But, when the app rel

A simple Discord bot that aims to provide a snapshot of the join logs given a range of time for servers.
A simple Discord bot that aims to provide a snapshot of the join logs given a range of time for servers.

🧋 What is Humpy Dumpy? Humpy Dumpy is a simple Discord bot that aims to provide a snapshot of the join logs given a range of time for servers. It was

Utility logger library for storing logs into database and push them to remote server for debugging
Utility logger library for storing logs into database and push them to remote server for debugging

HyperLog Android Overview Log format Download Initialize Usage Get Logs in a File Push Logs Files to Remote Server Sample Testing Endpoint using Reque

Convert OkHttp requests into curl logs.

Ok2Curl Convert OkHttp requests into curl logs. Usage Add library to project dependencies. Library is hosted on jcenter. repositories { jcenter()

Source++ is an open-source live coding platform. Add breakpoints, logs, metrics, and tracing to live production applications
Source++ is an open-source live coding platform. Add breakpoints, logs, metrics, and tracing to live production applications

Source++ is an open-source live coding platform. Add breakpoints, logs, metrics, and distributed tracing to live production software in real-time on-d

SimpleCloud-haste-module - SimpleCloud module for uploading the logs of your services to hastebin

SimpleCloud Haste Module A SimpleCloud Module for uploading the current logs of

Pluto Logger is a Pluto plugin to manage and share your Debug logs

Pluto Logger Plugin Pluto Logger is a Pluto plugin to manage and share your Debug logs. It also comes with Timber support. 🖇 Integrate plugin in your

A light lib that helps and centralize logs in your application.
A light lib that helps and centralize logs in your application.

BadgeLog (Kotlin version) For the iOS swift version, see this page BadgeLog is an Android Kotlin library that helps you manage logs within your applic

FileLogger - a library for saving logs on Files with custom-formatter on background I/O threads, mobile-ready, android compatible,

The FileLogger is a library for saving logs on Files with custom-formatter on background I/O threads, mobile-ready, android compatible, powered by Java Time library for Android.

Simple, fast, efficient logging facade for Android apps

µlog Simple, fast, and efficient logging facade for Android apps. Inspired by Timber and Logcat. Features Lazy message evaluation Pluggable backends (

This is an Kotlin Library that enables Annotation-triggered method call logging for Kotlin Multiplatform.

This is an Kotlin Library that enables Annotation-triggered method call logging for Kotlin Multiplatform.

Releases(0.0.2)
Owner
null
Utility logger library for storing logs into database and push them to remote server for debugging

HyperLog Android Overview Log format Download Initialize Usage Get Logs in a File Push Logs Files to Remote Server Sample Testing Endpoint using Reque

HyperTrack 675 Nov 14, 2022
Pluto Logger is a Pluto plugin to manage and share your Debug logs

Pluto Logger Plugin Pluto Logger is a Pluto plugin to manage and share your Debug logs. It also comes with Timber support. ?? Integrate plugin in your

Pluto 1 Feb 8, 2022
FileLogger - a library for saving logs on Files with custom-formatter on background I/O threads, mobile-ready, android compatible,

The FileLogger is a library for saving logs on Files with custom-formatter on background I/O threads, mobile-ready, android compatible, powered by Java Time library for Android.

Abolfazl Abbasi 12 Aug 23, 2022
This is an Kotlin Library that enables Annotation-triggered method call logging for Kotlin Multiplatform.

This is an Kotlin Library that enables Annotation-triggered method call logging for Kotlin Multiplatform.

Jens Klingenberg 187 Dec 18, 2022
Kermit is a Kotlin Multiplatform logging utility with composable log outputs

Kermit is a Kotlin Multiplatform logging utility with composable log outputs. The library provides prebuilt loggers for outputting to platform logging tools such as Logcat and NSLog.

Touchlab 395 Jan 4, 2023
A tiny Kotlin API for cheap logging on top of Android's normal Log class.

A tiny Kotlin API for cheap logging on top of Android's normal Log class.

Square 849 Dec 23, 2022
A demonstration of Kotlin-logging with logback.

try-kotlin-logging A demonstration of Kotlin-logging with logback. Usage # output a log to STDOUT and file(myApp.log) $ ./gradlew run # => 2021-12-11

Hayato Tachikawa 1 Dec 13, 2021
Annotation-triggered method call logging for your debug builds.

Hugo Annotation-triggered method call logging for your debug builds. As a programmer, you often add log statements to print method calls, their argume

Jake Wharton 7.9k Dec 31, 2022
📄The reliable, generic, fast and flexible logging framework for Android

logback-android v2.0.0 Overview logback-android brings the power of logback to Android. This library provides a highly configurable logging framework

Tony Trinh 1.1k Jan 5, 2023
An in-display logging library for Android 📲

Vlog provides an easy and convenient way to access logs right on your phone.

girish budhwani 121 Dec 26, 2022