Logging
Learn how to use logging utilities to print to Logcat
Printing to Logcat is done using the functions found in Logging.kt
, such as debugLn
, verboseLn
, warnLn
and errorLn
.
Pass the String
or object you want to print to Logcat into the lamda parameter. Each one of them represent a Logcat Level to print into.
Using debugLn
will print a DEBUG message in the log, while warnLn
will log a WARNING and so on.
Example of usage
debugLn { "This is a debug message" } warnlLn { "Code was executed $count times" } errorLn { val result = runHeavyOperation() "Error! This is what happened: $result" }
No logging in release builds
Logging will take place only in debug builds. This is done according to the BuildConfig.DEBUG
.
This makes it safe for you to run heavy operations inside the passing lambdas as they will only run if logging is enabled.
To override this behavior and manually enable or disable logging use the setLogging()
function.
Last updated on August 4, 2021