An easy way to customize your log in Android.
There are various requirements for client logging.
Classification by log output destinations:
- Output to console
- Output to file
- Output to database
- Output to server
Classification by log content processing:
- Formatting logs
- Encrypting logs
- Compressing logs
- Appending information
Classification by development usability:
- Automatic tag generation
- One-time tags
- Support for format arguments
- Printing lists and maps
Different business scenarios may select and combine some of these logging options in any order, and may also add new logging processing logic.
Easylog allows you to freely combine your logging processing logic in any order.
Let's say, you have the following log processing process:
The origin log is divied into two process flow.
Or, another log processing process:
The origin log are classified and each has it own processing logic.
The log processing logic is like a Flexible production line. By EasyLog, it is easy to customize your own Flexible production line.
EasyLog is designed with chain of responsibility, each log processing logic is abstracted as anInterceptor<T>
. The Interceptors are not standalone, they are chained with each other. It means the output of previous Interceptor is the input of the next one.
EasyLog.addInterceptor(LogcatInterceptor()) // add logcat intercepter
EasyLog.addInterceptor(SinkInterceptor()) // add file interceptor which keeps log in file
EasyLog.log("abcd")
EasyLog.log(User(name = "taylor", age = 20))
val array = listOf(1,2,3)
EasyLog.list(array)// output ”[1, 2, 3]“
val users = listOf(
User(name = "peter", age = 18),
User(name = "joice", age = 20),
User(name = "martin", age = 10),
)
EasyLog.list(users) { it.name } // output ”[peter, joice, martin]“
val map = mapOf(
"a" to mapOf( "1" to true),
"b" to mapOf( "2" to false, "3" to true)
)
EasyLog.map(map)
output:
{
[a] = { [1] = true },
[b] = {
[2] = false,
[3] = true
}
}
Tag is auto-generated by default.
class UserManger {
fun print() {
EasyLog.log("taylor")
}
}
The auto-generated tag is "UserManager"
One-time tag is supported:
EasyLog.tag("test").log("abcd")
EasyLog.log("taylor", DEBUG)
Log level is supported by parameter not function
EasyLog.log("end %s", DEBUG, "ab")
EasyLog.interceptor(FrameInterceptor()).log("higlight")
EasyLog.log("after highlight")
output:
┌──────────────────────────────────────────────────────────────────────────
│highlight
└──────────────────────────────────────────────────────────────────────────
after highlight