Skip to content

wisdomtl/EasyLog

Repository files navigation

EasyLog

An easy way to customize your log in Android.

Background

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:

pic

The origin log is divied into two process flow.

Or, another log processing process:

pic2

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.

1. Initialization

EasyLog.addInterceptor(LogcatInterceptor()) // add logcat intercepter
EasyLog.addInterceptor(SinkInterceptor()) // add file interceptor which keeps log in file

2. Use it everywhere

log string

EasyLog.log("abcd")

log POJO

EasyLog.log(User(name = "taylor", age = 20))

log List

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]“

log Map

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
        }
    }

auto-generated/one-time tag

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")

log level supported

EasyLog.log("taylor", DEBUG)

Log level is supported by parameter not function

format arguments supported

EasyLog.log("end %s", DEBUG, "ab")

one-time interceptor

EasyLog.interceptor(FrameInterceptor()).log("higlight")
EasyLog.log("after highlight")

output:

┌──────────────────────────────────────────────────────────────────────────
│highlight                    
└──────────────────────────────────────────────────────────────────────────
after highlight

About

An easy way to customize log processing logic in the way just like a Flexible production line in Android.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages