-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 36 additions & 13 deletions
49
modules/logger/src/commonMain/kotlin/com/sphereon/oid/fed/logger/Logger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
package com.sphereon.oid.fed.common.logging | ||
package com.sphereon.oid.fed.logger | ||
|
||
import co.touchlab.kermit.Logger | ||
import co.touchlab.kermit.* | ||
import co.touchlab.kermit.Logger as KermitLogger | ||
import kotlinx.datetime.Clock | ||
|
||
object Logger { | ||
object TimestampFormatter : MessageStringFormatter { | ||
override fun formatMessage(severity: Severity?, tag: Tag?, message: Message): String { | ||
val sb = StringBuilder() | ||
val now = Clock.System.now() | ||
sb.append("[${severity.toString().uppercase()}] ") | ||
sb.append(now.toString()) | ||
sb.append(" ") | ||
sb.append(super.formatMessage(null, tag, message)) | ||
return sb.toString() | ||
} | ||
} | ||
|
||
class Logger(private val tag: String = "") { | ||
fun verbose(message: String, tag: String = this.tag) { | ||
KermitLogger.v(tag = tag, messageString = message) | ||
} | ||
|
||
fun verbose(tag: String, message: String) { | ||
Logger.v(tag = tag, messageString = message) | ||
fun debug(message: String, tag: String = this.tag) { | ||
KermitLogger.d(tag = tag, messageString = message) | ||
} | ||
|
||
fun debug(tag: String, message: String) { | ||
Logger.d(tag = tag, messageString = message) | ||
fun info(message: String, tag: String = this.tag) { | ||
KermitLogger.i(tag = tag, messageString = message) | ||
} | ||
|
||
fun info(tag: String, message: String) { | ||
Logger.i(tag = tag, messageString = message) | ||
fun warn(message: String, tag: String = this.tag) { | ||
KermitLogger.w(tag = tag, messageString = message) | ||
} | ||
|
||
fun warn(tag: String, message: String) { | ||
Logger.w(tag = tag, messageString = message) | ||
fun error(message: String, throwable: Throwable? = null, tag: String = this.tag) { | ||
KermitLogger.e(tag = tag, messageString = message, throwable = throwable) | ||
} | ||
|
||
fun error(tag: String, message: String, throwable: Throwable? = null) { | ||
Logger.e(tag = tag, messageString = message, throwable = throwable) | ||
fun setMinSeverity(severity: Severity) = KermitLogger.setMinSeverity(severity) | ||
fun setLogWriters() = KermitLogger.setLogWriters(platformLogWriter(TimestampFormatter)) | ||
|
||
object Static { | ||
fun tag(tag: String = "", severity: Severity = Severity.Info) = | ||
Logger(tag).also { it.setMinSeverity(severity) }.also { it.setLogWriters() } | ||
} | ||
} | ||
|
||
val DefaultLogger = Logger.Static.tag("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...id-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/ClientConstants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.sphereon.oid.fed.client | ||
|
||
import com.sphereon.oid.fed.logger.Logger | ||
|
||
object ClientConstants { | ||
private const val LOG_NAMESPACE = "sphereon:oid:fed:client" | ||
val LOG = Logger.Static.tag(LOG_NAMESPACE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters