All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.com.adamratzman.spotify.SpotifyLogger.kt Maven / Gradle / Ivy

There is a newer version: 4.1.3
Show newest version
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
package com.adamratzman.spotify

public actual class SpotifyLogger actual constructor(public actual var enabled: Boolean) {
    private val redString = "\u001B[31m"
    private val orangeString = "\u001B[33m"
    private val resetString = "\u001B[0m"

    public actual fun logInfo(message: String) {
        if (enabled) println("Spotify Logger Info: $message")
    }

    public actual fun logWarning(message: String) {
        if (enabled) println("${orangeString}Spotify Logger Warning: $message$resetString")
    }

    public actual fun logError(fatal: Boolean, message: String?, throwable: Throwable?) {
        if (!enabled) return

        val error = StringBuilder(redString).apply {
            append("Spotify Logger ")
            if (fatal) append("FATAL")
            else append("Error")
            if (message != null) {
                append(": ")
                append(message)
            }
            append(resetString)
        }.toString()
        System.err.println(error)
        throwable?.printStackTrace()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy