Skip to content

Commit

Permalink
update dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhizi715 committed Oct 14, 2021
1 parent 4f27a1c commit 9d9bacc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.net.Uri
import android.os.Bundle
import cn.salesuite.saf.kotlin.domain.User
import com.safframework.log.L
import com.safframework.log.utils.getFullStackTrace


/**
Expand Down Expand Up @@ -53,6 +54,8 @@ class BasicActivity : Activity() {

val uri = Uri.parse ("http://www.java2s.com:8080/yourpath/fileName.htm?stove=10&path=32&id=4#harvic")
L.json(uri)

L.e(NullPointerException())
}

}
48 changes: 3 additions & 45 deletions core/src/main/java/com/safframework/log/L.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.safframework.log

import android.util.Log
import com.safframework.log.bean.JSONConfig
import com.safframework.log.converter.Converter
import com.safframework.log.formatter.BorderFormatter
Expand Down Expand Up @@ -171,53 +170,32 @@ object L {
fun e(throwable: Throwable?) = e(TAG, getFullStackTrace(throwable))

@JvmStatic
fun e(msg: String?) = e(TAG,msg)

@JvmStatic
fun e(tag: String?, msg: String?) = printLog(LogLevel.ERROR,tag,msg)
fun e(tag: String?, throwable: Throwable?) = e(tag, getFullStackTrace(throwable))

@JvmStatic
fun e(msg: String?, tr: Throwable) = e(TAG,msg,tr)
fun e(msg: String?) = e(TAG,msg)

@JvmStatic
fun e(tag: String?, msg: String?, tr: Throwable) = printThrowable(LogLevel.ERROR,tag,msg,tr)
fun e(tag: String?, msg: String?) = printLog(LogLevel.ERROR,tag,msg)

@JvmStatic
fun w(msg: String?) = w(TAG,msg)

@JvmStatic
fun w(tag: String?, msg: String?) = printLog(LogLevel.WARN,tag,msg)

@JvmStatic
fun w(msg: String?, tr: Throwable) = w(TAG,msg,tr)

@JvmStatic
fun w(tag: String?, msg: String?, tr: Throwable) = printThrowable(LogLevel.WARN,tag,msg,tr)

@JvmStatic
fun i(msg: String?) = i(TAG,msg)

@JvmStatic
fun i(tag: String?, msg: String?) = printLog(LogLevel.INFO,tag,msg)

@JvmStatic
fun i(msg: String?, tr: Throwable) = i(TAG,msg,tr)

@JvmStatic
fun i(tag: String?, msg: String?, tr: Throwable) = printThrowable(LogLevel.INFO,tag,msg,tr)

@JvmStatic
fun d(msg: String?) = d(TAG,msg)

@JvmStatic
fun d(tag: String?, msg: String?) = printLog(LogLevel.DEBUG,tag,msg)

@JvmStatic
fun d(msg: String?, tr: Throwable) = d(TAG,msg,tr)

@JvmStatic
fun d(tag: String?, msg: String?, tr: Throwable) = printThrowable(LogLevel.DEBUG,tag,msg,tr)

/**
* 使用特定的 printer 进行打印日志
*/
Expand All @@ -244,26 +222,6 @@ object L {
}
}

private fun printThrowable(logLevel: LogLevel, tag: String?, msg: String?, tr: Throwable) {

if (logLevel.value <= L.logLevel.value) {

if (tag != null && tag.isNotEmpty() && msg != null && msg.isNotEmpty()) {

when(logLevel) {

LogLevel.ERROR -> Log.e(tag, msg, tr)

LogLevel.WARN -> Log.w(tag, msg, tr)

LogLevel.INFO -> Log.i(tag, msg, tr)

LogLevel.DEBUG -> Log.d(tag, msg, tr)
}
}
}
}

/**
* 将任何对象转换成json字符串进行打印
*/
Expand Down
16 changes: 0 additions & 16 deletions core/src/main/java/com/safframework/log/extension/L+Extension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,18 @@ inline fun L.e(msg: msgFunction) = e(msg.invoke())

inline fun L.e(tag: String?, msg: msgFunction) = e(tag, msg.invoke())

inline fun L.e(msg: msgFunction, tr: Throwable) = e(msg.invoke(), tr)

inline fun L.e(tag: String?, msg: msgFunction, tr: Throwable) = e(tag, msg.invoke(), tr)

inline fun L.w(msg: msgFunction) = w(msg.invoke())

inline fun L.w(tag: String?, msg: msgFunction) = w(tag, msg.invoke())

inline fun L.w(msg: msgFunction, tr: Throwable) = w(msg.invoke(), tr)

inline fun L.w(tag: String?, msg: msgFunction, tr: Throwable) = w(tag, msg.invoke(), tr)

inline fun L.i(msg: msgFunction) = i(msg.invoke())

inline fun L.i(tag: String?, msg: msgFunction) = i(tag, msg.invoke())

inline fun L.i(msg: msgFunction, tr: Throwable) = i(msg.invoke(), tr)

inline fun L.i(tag: String?, msg: msgFunction, tr: Throwable) = i(tag, msg.invoke(), tr)

inline fun L.d(msg: msgFunction) = d(msg.invoke())

inline fun L.d(tag: String?, msg: msgFunction) = d(tag, msg.invoke())

inline fun L.d(msg: msgFunction, tr: Throwable) = d(msg.invoke(), tr)

inline fun L.d(tag: String?, msg: msgFunction, tr: Throwable) = d(tag, msg.invoke(), tr)

inline fun L.json(any:anyFunction) = json(any.invoke())

inline fun L.json(any:anyFunction,jsonConfig: JSONConfig) = json(any.invoke(),jsonConfig)

0 comments on commit 9d9bacc

Please sign in to comment.