Sie Anko
Bibliothek verwenden können, es zu tun. Sie würden Code wie unten haben:
class MyActivity : Activity(), AnkoLogger {
private fun someMethod() {
info("This is my first app and it's awesome")
debug(1234)
warn("Warning")
}
}
oder Sie können auch diese kleine in Kotlin Bibliothek geschrieben verwenden genannt StaticLog
Code dann würde wie folgt aussieht:
Log.info("This is an info message")
Log.debug("This is a debug message")
Log.warn("This is a warning message","WithACustomTag")
Log.error("This is an error message with an additional Exception for output", "AndACustomTag", exception)
Log.logLevel = LogLevel.WARN
Log.info("This message will not be shown")\
Die zweite Lösung besser wäre, wenn Sie möchten,
Log.newFormat {
line(date("yyyy-MM-dd HH:mm:ss"), space, level, text("/"), tag, space(2), message, space(2), occurrence)
}
oder Filter, beispielsweise: ein Ausgabeformat für Protokollierungsverfahren wie definiert
Log.filterTag = "filterTag"
Log.info("This log will be filtered out", "otherTag")
Log.info("This log has the right tag", "filterTag")
Wenn Sie bereits Jake Whartons Protokollbibliothek Timber
verwendet haben, überprüfen Sie dieses Projekt: https://github.com/ajalt/timberkt.
auch zu prüfen: Logging in Kotlin & Android: AnkoLogger vs kotlin-logging
Hoffen, dass es
Alle Java-Methoden arbeiten auch mit Kotlin. Was genau meinst du mit "es scheint zu funktionieren"? – yole