Skip to content

Commit

Permalink
增加写入拦截器,可自定义写入本地/上传服务器
Browse files Browse the repository at this point in the history
  • Loading branch information
tohodog committed Dec 9, 2020
1 parent 7d2fb20 commit 6b8779f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Android Log Persistence Lightweight Framework 安卓日志持久化轻量级框
```
QLog.init(getApplication()); //初始化,默认路径-> /Android/data/包名/files/QLog
QLog.i("info日志"); //写入-> 2020-10-20_QLog.txt
QLog.e("login", "error日志"); //写入-> 2020-10-20_login.txt
QLog.i("info日志"); //写入-> 2020-10-20_QLog.log
QLog.e("login", "error日志"); //写入-> 2020-10-20_login.log
2020-10-20 08:27:00.360 INFO [main] info日志
2020-10-20 08:27:00.360 ERROR [Thread-2] error日志
Expand All @@ -41,7 +41,7 @@ dependencies {
## 高级
```
QLog.init(QLogConfig.Build(getApplication())
.path("/xxx")//日志目录,一般不要动安卓10限制了外部目录访问了
.path(getExternalFilesDir(null) + "/QLog")//日志目录,一般不要动安卓10限制了外部目录访问了
.buffSize(128 * 1024)//buff大小
.delay(10000)//延迟写入时间
.day(30)//日志保留30天,默认无限制
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/com/qsinong/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ protected void onCreate(Bundle savedInstanceState) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 0);

QLog.init(QLogConfig.Build(getApplication())
.buffSize(256 * 1024)//buff大小
.delay(3000)//延迟写入时间
.day(1)//日志保留30天,默认无限制
.methodCount(0)//打印调用方法名
.path(getExternalFilesDir(null) + "/QLog")//日志目录,一般不要动安卓10限制了外部目录访问了
.buffSize(128 * 1024)//buff大小
.delay(10000)//延迟写入时间
.day(30)//日志保留30天,默认无限制
.methodCount(1)//打印调用方法名
.debug(BuildConfig.DEBUG)//true会输出控制台,上线可关掉
// .logFormat(new LogFormat() {//自定义日记格式
// @Override
// public String format(Level level, String time, String log, String stact) {
// return level + " " + time + " " + log + " --" + stact;
// return level + " " + time + " " + log + " ~" + stact;
// }
// })
.writeData(new WriteData() {//自定义写入/上传操作
.writeData(new WriteData() {//写入拦截,可自定义写入/上传操作
@Override
public boolean writeData(String folder, String fileName, byte[] bytes) throws Exception {
return false;//false会继续执行写入, true不继续执行
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/qsinong/example/single/QLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public static final class Builder {

private Builder(Application application) {
this.application = application;
this.path = application.getExternalFilesDir(null) + "/Qlog";
this.path = application.getExternalFilesDir(null) + "/QLog";
}

public QLogConfig build() {
Expand Down Expand Up @@ -437,7 +437,7 @@ public interface WriteData {
boolean writeData(String folder, String fileName, byte[] bytes) throws Exception;
}

private enum Level {
public enum Level {
DEBUG,
INFO,
WARING,
Expand Down
2 changes: 1 addition & 1 deletion qlog/src/main/java/com/qsinong/qlog/QLogConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static final class Builder {

private Builder(Application application) {
this.application = application;
this.path = application.getExternalFilesDir(null) + "/Qlog";
this.path = application.getExternalFilesDir(null) + "/QLog";
}

public QLogConfig build() {
Expand Down

0 comments on commit 6b8779f

Please sign in to comment.