Coder Social home page Coder Social logo

insanusmokrassar / kslog Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 0.0 1.07 MB

Simple multiplatform logging in Kotlin

Home Page: https://docs.inmo.dev/kslog/index.html

License: MIT License

Kotlin 99.01% Shell 0.99%
kotlin-android kotlin-js kotlin-jvm kotlin-logging kotlin-multiplatform-library kotlin kotlin-native

kslog's Introduction

KSLog

It is simple and easy-to-use tool for logging on the most popular platforms in Kotlin Multiplatform:

JVM Android Js ARM x64 ARM x32 Linux x64

KDocs Tutorials

By default, KSLog is using built-in tools for logging on each supported platform:

  • java.util.logging.Logger for JVM
  • android.util.Log for Android
  • Console for JS

But you always may create your logger and customize as you wish:

KSLog.default = KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
    // do your logging
}

This library also supports native targets in experimental mode. By default all native targets will use simple printing in the console

How to use

Fast-travel

Just use some boring extensions like:

KSLog.i("Some message")
// OR
KSLog.i("Some tag", "Some message")
// OR
KSLog.i("Some tag", "Some message", IllegalArgumentException("So, that is exception :)"))
// OR
KSLog.i("Some optional tag", Exception("Optional")) { "Lazy inited message" }
// OR
KSLog.iS("Some optional tag", Exception("Optional")) { "Lazy inited message for suspendable calculation of text" }
// OR EVEN
KSLog.l(LogLevel.INFO, "Some tag", "Some message", IllegalArgumentException("So, that is exception :)"))
// OR
KSLog.l(LogLevel.INFO, "Some optional tag", IllegalArgumentException("So, that is exception :)")) { "And lazily inited message" }

A little bit deeper

There are several important "terms" in context of this library:

  • Default logger (available via KSLog.default or simply KSLog)
  • Local logger (can be created via KSLog functions and passed anywhere as KSLog)
  • Logging shortcuts like KSLog.i/KSLog.info
  • Built-in extension Any.logger which allow you to create logger binded to the default with the tag based on the class of receiver
    • Be careful with the receivers: if you will use some extension like apply, the receiver will be different with your class inside of that apply

Every logging extension (like KSLog.i) have its analog with lazy inited message text and the same one with suffix S (like KSLog.iS) for the suspendable message calculation.

Default logger can be created by passing defaultTag and one of variants log level filters: set or minimal loggable level. In JVM you also may setup any logger as base logger for default realizations of KSLog. Besides, you may use your own callback (on any target platform) as output of logging:

val logger = KSLog { logLevel, optionalTag, message, optionalThrowable ->
    println("[$logLevel] $optionalTag - $message: $optionalThrowable.stackTraceToString()")
}

In the example above we will take the logger which will just print incoming data as common output.

Installation

Maven Central

Gradle

implementation "dev.inmo:kslog:$kslog_version"

Maven

<dependency>
  <groupId>dev.inmo</groupId>
  <artifactId>kslog</artifactId>
  <version>${kslog_version}</version>
</dependency>

kslog's People

Contributors

akkihi avatar insanusmokrassar avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kslog's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • Update actions/checkout action to v4
  • Update actions/setup-java action to v4
  • Update peaceiris/actions-gh-pages action to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/kdocs.yml
  • actions/checkout v2
  • actions/setup-java v1
  • peaceiris/actions-gh-pages v3
.github/workflows/publish.yml
  • actions/checkout v2
  • actions/setup-java v1
gradle
gradle.properties
defaultAndroidSettings.gradle
dokka.gradle
github_release.gradle
publish.gradle
settings.gradle
build.gradle
gradle/libs.versions.toml
  • org.jetbrains.kotlin:kotlin-stdlib 2.0.10
  • org.jetbrains.kotlin:kotlin-test-common 2.0.10
  • org.jetbrains.kotlin:kotlin-test-annotations-common 2.0.10
  • org.jetbrains.kotlin:kotlin-test-junit 2.0.10
  • org.jetbrains.kotlin:kotlin-test-js 2.0.10
  • androidx.test.ext:junit 1.2.1
  • androidx.test.espresso:espresso-core 3.6.1
  • com.android.tools.build:gradle 8.3.2
  • com.getkeepsafe.dexcount:dexcount-gradle-plugin 4.0.0
  • org.jetbrains.kotlin:kotlin-gradle-plugin 2.0.10
  • org.jetbrains.dokka:dokka-gradle-plugin 1.9.20
  • com.github.breadmoirai:github-release 2.5.2
  • org.jetbrains.kotlin.multiplatform 2.0.10
  • org.jetbrains.dokka 1.9.20
  • com.github.ben-manes.versions 0.51.0
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.9

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.