Coder Social home page Coder Social logo

logger's Introduction

Maven Central maintenance-status

🪵 Logger

Minimalistic Logger for Kotlin Multiplatform from one of my projects, shared with the awesome Kotlin community.

Architecture diagram

Usage

// Initialize
class App : Application() {
    override fun onCreate() {
        initializeLogger {
            registerAndroidLogSink()
            registerPrintlnSink() // default, if no sinks are configured
            registerMemoryRingSink()
            loggableLevel = if (isDebugBuild) Everyting else InfoAndSevere
        }
    }
}

// Use logger
private const val TAG = "Reader"

class Reader {
    init {
        i(TAG) { "created: size=${bytes?.size}" } // info
        d(TAG) { "created: size=${bytes?.size}" } // debug
    }

    suspend fun readData() {
        try {
            httpClient.post("read-data")
        } catch (e: Exception) {
            w(TAG, e) { "read-data failed" } // warning
            e(TAG, e) { "read-data failed" } // error
        }
    }
}

Dependencies

In gradle/libs.versions.toml

[versions]
kotlin = "2.0.0"
logger = "0.3"

[libraries]
logger = { module = "de.halfbit:logger", version.ref = "logger" }

[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }

In shared/build.gradle.kts

plugins {
    alias(libs.plugins.kotlin.multiplatform)
}

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation(libs.logger)
        }
    }
}

Release

  1. Bump version in root.publication.gradle.kts of the root project
  2. ./gradlew clean build publishAllPublicationsToCentralRepository

Release Notes

  • 0.3 MemoryRingSync prints log entries lazily.
  • 0.2 Improve log layouts for Println and MemoryRing sinks.
  • 0.1 Initial release

License

Copyright 2024 Sergej Shafarenka, www.halfbit.de

You are FREE to use, copy, redistribute, remix, transform, and build 
upon the material or its derivative FOR ANY LEGAL PURPOSES.

Any distributed derivative work containing this material or parts 
of it must have this copyright attribution notices.

The material is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
OR CONDITIONS OF ANY KIND, either express or implied.

logger's People

Contributors

sergejsha avatar

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.