parent
							
								
									1d0ad28e81
								
							
						
					
					
						commit
						33d7c35f67
					
				@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					package com.common.commonlib.log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 日志敏感信息处理
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					object LogSecureHelper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 一个间隔一个将数据替换成*
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    fun cast2Star(source: String): String {
 | 
				
			||||||
 | 
					        val sourceTemp = source.toCharArray()
 | 
				
			||||||
 | 
					        for (item in sourceTemp.withIndex()) {
 | 
				
			||||||
 | 
					            if (item.index / 2 == 0) {
 | 
				
			||||||
 | 
					                sourceTemp[item.index] = '*'
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return sourceTemp.toString()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,97 @@
 | 
				
			|||||||
 | 
					package com.common.commonlib.log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.util.Log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					object Logger {
 | 
				
			||||||
 | 
					    var commonTag = ""
 | 
				
			||||||
 | 
					    var needSecurity = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun init(tag: String, security: Boolean) {
 | 
				
			||||||
 | 
					        commonTag = tag
 | 
				
			||||||
 | 
					        needSecurity = security
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun w(msg: Any?) {
 | 
				
			||||||
 | 
					        w(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun d(msg: Any?) {
 | 
				
			||||||
 | 
					        d(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun i(msg: Any?) {
 | 
				
			||||||
 | 
					        i(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun e(msg: Any?) {
 | 
				
			||||||
 | 
					        e(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun w(msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        w(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun d(msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        d(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun i(msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        i(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun e(msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        e(commonTag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun w(tag: String, msg: Any?) {
 | 
				
			||||||
 | 
					        w(tag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun d(tag: String, msg: Any?) {
 | 
				
			||||||
 | 
					        d(tag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun i(tag: String, msg: Any?) {
 | 
				
			||||||
 | 
					        i(tag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun e(tag: String, msg: Any?) {
 | 
				
			||||||
 | 
					        e(tag, msg.toString(), needSecurity)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun w(tag: String, msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        Log.w(
 | 
				
			||||||
 | 
					            tag, if (needSecurity)
 | 
				
			||||||
 | 
					                LogSecureHelper.cast2Star(msg.toString())
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                msg.toString()
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun d(tag: String, msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        Log.d(
 | 
				
			||||||
 | 
					            tag, if (needSecurity)
 | 
				
			||||||
 | 
					                LogSecureHelper.cast2Star(msg.toString())
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                msg.toString()
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun i(tag: String, msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        Log.i(
 | 
				
			||||||
 | 
					            tag, if (needSecurity)
 | 
				
			||||||
 | 
					                LogSecureHelper.cast2Star(msg.toString())
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                msg.toString()
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun e(tag: String, msg: Any?, needSecurity: Boolean) {
 | 
				
			||||||
 | 
					        Log.e(
 | 
				
			||||||
 | 
					            tag, if (needSecurity)
 | 
				
			||||||
 | 
					                LogSecureHelper.cast2Star(msg.toString())
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                msg.toString()
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Loading…
					
					
				
		Reference in New Issue