Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugly增加自定义日志支持 #138

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.UpgradeInfo;
import com.tencent.bugly.beta.upgrade.UpgradeListener;
import com.tencent.bugly.crashreport.BuglyLog;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.HashMap;
Expand Down Expand Up @@ -153,6 +154,45 @@ public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean i
} else if (call.method.equals("postCatchedException")) {
postException(call);
result(null);
} else if (call.method.equals("BuglyLog")) {
String tag ="";
if (call.hasArgument("tag")) {
tag = call.argument("tag");
}
int level = 4;
if (call.hasArgument("level")) {
level = call.argument("level");
}
String log = "";
if (call.hasArgument("log")) {
log = call.argument("log");
}
int cache = 10;
if (call.hasArgument("cache")) {
cache = call.argument("cache");
BuglyLog.setCache(cache * 1024);
}
switch (level){
case 5:
BuglyLog.v(tag, log);
break;
case 4:
BuglyLog.d(tag, log);
break;
case 3:
BuglyLog.i(tag, log);
break;
case 2:
BuglyLog.w(tag, log);
break;
case 1:
BuglyLog.e(tag, log);
break;
default:
BuglyLog.d(tag, log);
break;
}
result(null);
} else {
result.notImplemented();
isResultSubmitted = true;
Expand Down
10 changes: 10 additions & 0 deletions ios/Classes/FlutterBuglyPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[Bugly setUserValue:value forKey:key];
}
result(nil);
}else if([@"BuglyLog" isEqualToString:call.method]){///自定义日志
NSString *tag = call.arguments[@"tag"];
NSString *log = call.arguments[@"log"];
NSInteger levelInteger =4;
NSNumber *level = call.arguments[@"level"];
if (level!=nil) {
levelInteger = [level integerValue];
}
BLYLog(levelInteger, tag, log);
result(nil);
}else {
result(FlutterMethodNotImplemented);
}
Expand Down
34 changes: 34 additions & 0 deletions lib/src/flutter_bugly.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,38 @@ class FlutterBugly {
_onCheckUpgrade.close();
_postCaught = false;
}

///自定义日志功能
///用户传入TAG和日志内容。该日志将在Logcat输出,并在发生异常时上报。
///使用BuglyLog接口时,为了减少磁盘IO次数,我们会先将日志缓存在内存中。当缓存大于一定阈值(默认10K),会将它持久化至文件
///e:1 w:2 i:3 d:4 v:5
static Future<Null> buglyLog({
required String tag,
required String log,
int level =4,///默认debug
int? cache
}) async {
if(cache != null){
if(cache >30){//接口设置缓存大小,范围为0-30K
cache =30;
} else if(cache <0){//默认10K
cache =10;
}
Map<String, Object> map = {
"tag": tag,
"log": log,
"level":level,
"cache":cache
};
await _channel.invokeMethod('BuglyLog', map);
} else {
Map<String, Object> map = {
"tag": tag,
"log": log,
"level":level
};
await _channel.invokeMethod('BuglyLog', map);
}
}

}