Getting started with Canard
This guide assumes a JVM target. Canard works exactly the same on all targets that are supported by Kotlin (JVM, Android, JS, Native). |
Install
In your build.gradle.kts
file, add the Maven Central repository:
repositories {
mavenCentral()
}
Then add the dependency:
dependencies {
implementation 'org.kodein.log:canard:0.18.0'
}
More detailed installation guide here.
Create and use a Logger
Before being able to log anything, you need to create a LoggerFactory
,
to define the format of your logs and on which frontend they should be sent.
-
create a
LoggerFactory
val loggerFactory = LoggerFactory.default (1)
1 Initialize a LoggerFactory
with the default output format. -
create a
Logger
class MyController { private val logger = LoggerFactory.default.newLogger<MyController>() (1) }
1 Initialize a Logger
from a givenLoggerFactory
.Thanks to the awesome Kotlin type system we can even go further, without explicitly naming the Tag used for logging:
class MyController(private val loggerFactory: LoggerFactory) { private val logger = newLogger(loggerFactory) (1) }
1 Initialize a Logger
from a givenLoggerFactory
, implicitly tagged withMyController
. -
Use the logger
logger.info { "Well done..." } logger.warning { "...you have completed the Getting Started guide." }
Logging levels available: debug
/info
/warning
/error
.
More detailed on Logger
initialization and usage.
If you want to know more about frontend implementation you can read Working with custom frontends.