Logging

Message type notice
On this page all the messages will be just simple String, but you may pass any object as the message

As has been said in the setup section, this library contains next levels of logging with their default representations on each platform:

Weight (by order) LogLevel name JS JVM Loggers Android
0 DEBUG console.log Level.FINEST Log.d
1 VERBOSE console.info Level.FINE Log.v
2 INFO console.info Level.INFO Log.i
3 WARNING console.warn Level.WARNING Log.w
4 ERROR console.error Level.SEVERE Log.e
5 ASSERT console.error Level.SEVERE Log.wtf

Each of these levels have fullname and shortname shortcat extensions:

And any of these shortcuts may accept one of several arguments combinations:

So, when you want to log some expected exception, there are three common ways to do it:

val logger = KSLog.default

// with callback
logger.info(tag, throwable) {
  "Some your message for this event"
}

// with suspendable callback
logger.infoS(tag, throwable) {
  withContext(Dispatchers.Default) {
    "Some your message for this event"
  }
}

// Just with message
logger.info("Some your message for this event", throwable)

// With message and tag as strings
logger.info(tag, "Some your message for this event", throwable)

Of course, any of this calls can be shortenned:

val logger = KSLog.default

// with callback
logger.i(tag, throwable) {
  "Some your message for this event"
}

// with suspendable callback
logger.iS(tag, throwable) {
  withContext(Dispatchers.Default) {
    "Some your message for this event"
  }
}

// Just with message
logger.i("Some your message for this event", throwable)

// With message and tag as strings
logger.i(tag, "Some your message for this event", throwable)

There is special shortcat - for base performLog. In that case the only change is that you will require to pass the LogLevel more obviously:

val logger = KSLog.default

// with callback
logger.log(LogLevel.INFO, tag, throwable) {
  "Some your message for this event"
}

// with suspendable callback
logger.logS(LogLevel.INFO, tag, throwable) {
  withContext(Dispatchers.Default) {
    "Some your message for this event"
  }
}

// Just with message
logger.log(LogLevel.INFO, "Some your message for this event", throwable)

// With message and tag as strings
logger.log(LogLevel.INFO, tag, "Some your message for this event", throwable)

OR

val logger = KSLog.default

// with callback
logger.l(LogLevel.INFO, tag, throwable) {
  "Some your message for this event"
}

// with suspendable callback
logger.lS(LogLevel.INFO, tag, throwable) {
  withContext(Dispatchers.Default) {
    "Some your message for this event"
  }
}

// Just with message
logger.l(LogLevel.INFO, "Some your message for this event", throwable)

// With message and tag as strings
logger.l(LogLevel.INFO, tag, "Some your message for this event", throwable)

Revision #7
Created 8 June 2022 19:38:39 by InsanusMokrassar
Updated 30 July 2022 09:15:11 by InsanusMokrassar