Skip to content

Commit

Permalink
feat: 日志工具类升级
Browse files Browse the repository at this point in the history
  • Loading branch information
keepactive committed Oct 13, 2021
1 parent bfe9de7 commit b5d4428
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/com/xiaojinzi/support/demo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import android.app.Application
import androidx.multidex.MultiDex
import com.xiaojinzi.component.Component
import com.xiaojinzi.component.Config
import com.xiaojinzi.support.ktx.newUUid
import com.xiaojinzi.support.util.LogSupport

class App: Application() {
class App : Application() {

override fun onCreate() {
super.onCreate()
Expand All @@ -23,7 +24,7 @@ class App: Application() {
.build()
)

LogSupport.e("天呐")
LogSupport.e(content = "天呐", keywords = arrayOf("我的", "你的"))

}

Expand Down
46 changes: 35 additions & 11 deletions lib-ktx/src/main/java/com/xiaojinzi/support/util/LogSupport.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.xiaojinzi.support.util

import android.util.Log
import java.lang.Exception

/**
* 日志的帮助类
Expand All @@ -19,28 +18,53 @@ object LogSupport {
}

@JvmOverloads
fun v(content: String, tag: String = defaultTag) {
Log.v(tag, content)
fun v(content: String, tag: String = defaultTag, vararg keywords: String) {
val keywordStr = if (keywords.isNullOrEmpty()) {
""
} else {
"[${keywords.joinToString()}]"
}
Log.v(tag, "$keywordStr $content")
}

@JvmOverloads
fun d(content: String, tag: String = defaultTag) {
Log.d(tag, content)
fun d(content: String, tag: String = defaultTag, vararg keywords: String) {
val keywordStr = if (keywords.isNullOrEmpty()) {
""
} else {
"[${keywords.joinToString()}]"
}
Log.d(tag, "$keywordStr $content")
}

@JvmOverloads
fun i(content: String, tag: String = defaultTag) {
Log.i(tag, content)
fun i(content: String, tag: String = defaultTag, vararg keywords: String) {
val keywordStr = if (keywords.isNullOrEmpty()) {
""
} else {
"[${keywords.joinToString()}]"
}
Log.i(tag, "$keywordStr $content")
}

@JvmOverloads
fun e(content: String, tag: String = defaultTag) {
Log.e(tag, content)
fun e(content: String, tag: String = defaultTag, vararg keywords: String) {
val keywordStr = if (keywords.isNullOrEmpty()) {
""
} else {
"[${keywords.joinToString()}]"
}
Log.e(tag, "$keywordStr $content")
}

@JvmOverloads
fun w(content: String, tag: String = defaultTag) {
Log.w(tag, content)
fun w(content: String, tag: String = defaultTag, vararg keywords: String) {
val keywordStr = if (keywords.isNullOrEmpty()) {
""
} else {
"[${keywords.joinToString()}]"
}
Log.w(tag, "$keywordStr $content")
}

}

0 comments on commit b5d4428

Please sign in to comment.