author:wangyimiao

desc:添加统一打日志的方法
master
yimiao 3 years ago
parent 1d0ad28e81
commit 33d7c35f67

@ -3,11 +3,11 @@ package com.common.commonlibtest;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import com.common.commonlib.image.config.GlideHolderConfig; import com.common.commonlib.image.config.GlideHolderConfig;
import com.common.commonlib.image.config.GlideTransitionConfig; import com.common.commonlib.image.config.GlideTransitionConfig;
import com.common.commonlib.image.loader.ImageLoader; import com.common.commonlib.image.loader.ImageLoader;
import com.common.commonlib.log.Logger;
import com.common.commonlib.net.RequestCallBack; import com.common.commonlib.net.RequestCallBack;
import com.common.commonlib.net.interceptor.RequestHeadInterceptor; import com.common.commonlib.net.interceptor.RequestHeadInterceptor;
import com.common.commonlib.net.interceptor.ResponseHeadInterceptor; import com.common.commonlib.net.interceptor.ResponseHeadInterceptor;
@ -56,17 +56,17 @@ public class MainActivity extends AppCompatActivity {
loader.getHomeArticles(0, new RequestCallBack<ArticlesResponse>() { loader.getHomeArticles(0, new RequestCallBack<ArticlesResponse>() {
@Override @Override
public void onResult(ArticlesResponse result) { public void onResult(ArticlesResponse result) {
Log.d(TAG, result.getData().toString()); Logger.INSTANCE.d(TAG, result.getData().toString());
} }
@Override @Override
public void onError(@Nullable String error) { public void onError(@Nullable String error) {
Log.d(TAG, "onError"); Logger.INSTANCE.d(TAG, "onError");
} }
@Override @Override
public void onComplete() { public void onComplete() {
Log.d(TAG, "onComplete"); Logger.INSTANCE.d(TAG, "onComplete");
} }
}); });
}); });
@ -82,17 +82,17 @@ public class MainActivity extends AppCompatActivity {
loader.getCollections(0, new RequestCallBack<CollectionResponse>() { loader.getCollections(0, new RequestCallBack<CollectionResponse>() {
@Override @Override
public void onResult(CollectionResponse result) { public void onResult(CollectionResponse result) {
Log.d(TAG, "onResult"); Logger.INSTANCE.d(TAG, "onResult");
} }
@Override @Override
public void onError(@Nullable String error) { public void onError(@Nullable String error) {
Log.d(TAG, "onError"); Logger.INSTANCE.d(TAG, "onError");
} }
@Override @Override
public void onComplete() { public void onComplete() {
Log.d(TAG, "onComplete"); Logger.INSTANCE.d(TAG, "onComplete");
} }
}); });
}); });
@ -106,17 +106,17 @@ public class MainActivity extends AppCompatActivity {
new LoginLoader(interceptors).login("wang11", "wang456852", new RequestCallBack<LoginResponse>() { new LoginLoader(interceptors).login("wang11", "wang456852", new RequestCallBack<LoginResponse>() {
@Override @Override
public void onResult(LoginResponse result) { public void onResult(LoginResponse result) {
Log.d(TAG, "onResult"); Logger.INSTANCE.d(TAG, "onResult");
} }
@Override @Override
public void onError(@Nullable String error) { public void onError(@Nullable String error) {
Log.d(TAG, "onError"); Logger.INSTANCE.e(TAG, "onError");
} }
@Override @Override
public void onComplete() { public void onComplete() {
Log.d(TAG, "onComplete"); Logger.INSTANCE.i(TAG, "onComplete");
} }
}); });
}); });
@ -128,7 +128,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
FTPUtils.RESULT result = FTPUtils.INSTANCE.ftpUpload("192.168.101.215", "2221", "admin", "123456", filePath, fileName); FTPUtils.RESULT result = FTPUtils.INSTANCE.ftpUpload("192.168.101.215", "2221", "admin", "123456", filePath, fileName);
Log.i("wangym", result.name()); Logger.INSTANCE.d(result.name());
} }
}); });
thread.start(); thread.start();

@ -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…
Cancel
Save