Skip to content

Commit

Permalink
feat(sentry): sentry集成
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Oct 17, 2023
1 parent 2ada035 commit 4fb866f
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 1 deletion.
1 change: 1 addition & 0 deletions aop-utilcode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions aop-utilcode/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 33

defaultConfig {
minSdkVersion 19
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
api "androidx.startup:startup-runtime:1.1.0"
api 'org.aspectj:aspectjrt:1.9.5'
api 'com.github.hss01248.aop-android:logforaop:1.0.2'
api 'com.blankj:utilcodex:1.30.0'
implementation 'com.github.hss01248.utilcodeEnhance:sentry:1.3.5'
}
1 change: 1 addition & 0 deletions aop-utilcode/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-keep class com.blankj.utilcode.** { *; }
21 changes: 21 additions & 0 deletions aop-utilcode/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hss01248.aop.utilcode;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.hss01248.aop.utilcode.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions aop-utilcode/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hss01248.aop.utilcode">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.hss01248.aop.utilcode;


import com.blankj.utilcode.util.LogUtils;
import com.hss01248.sentry.SentryUtil;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class AspectLogUtils {

/**
* log(final int type, final String tag, final Object... contents)
* @param joinPoint
* @return
* @throws Throwable
*/
@Before("execution(* com.blankj.utilcode.util.LogUtils.log(..))")
public void weaveJoinPoint(JoinPoint joinPoint) throws Throwable {
int type = (int) joinPoint.getArgs()[0];
if(type < LogUtils.W){
return;
}
Object[] objects= (Object[]) joinPoint.getArgs()[2];
if(objects == null || objects.length ==0){
return;
}
SentryUtil.Builder builder = SentryUtil.create();
boolean hasThrowable = false;
int count = 0;
for (Object object : objects) {
if(object instanceof Throwable){
hasThrowable = true;
Throwable throwable = (Throwable) object;
builder.exception(throwable);
}else {
count++;
builder.addExtra("extra"+count,object+"");
}
}
String typeStr = "warn";
if(type == LogUtils.E){
typeStr = "error";
}else if(type == LogUtils.A){
typeStr = "assert";
}else if(type == LogUtils.W){
typeStr = "warn";
}else {
typeStr = type+"";
}
builder.addTag("logLevel",typeStr);
if(hasThrowable){
// builder.addExtra("extraMsg",joinPoint.getArgs()[0]+"");
}else {
builder.msg(objects[0]+"");
}
String tag = joinPoint.getArgs()[1]+"";
if(!tag.equals("") && !"null".equals(tag)){
builder.addTag("extraTag",joinPoint.getArgs()[1]+"");
}
builder.doReport();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hss01248.aop.utilcode;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ dependencies {

implementation 'com.github.hss01248.HttpUtil2:http:3.1.2'

implementation project(path: ':aop-utilcode')


}

Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/hss01248/flipperdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ThreadUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hjq.permissions.OnPermissionCallback;
Expand Down Expand Up @@ -350,4 +351,17 @@ public void onClick(DialogInterface dialog, int which) {
}).show();

}

public void logaop_warn(View view) {
LogUtils.w("waring log test");

}

public void logaop_error(View view) {
LogUtils.e("error log test");
}

public void logaop_throwable(View view) {
LogUtils.w(new RuntimeException("test warn log"));
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@
android:textAllCaps="false"
android:onClick="singleChooseDialog"
android:layout_width="match_parent"/>
<Button android:layout_height="wrap_content"
android:text="logaop_warn"
android:textAllCaps="false"
android:onClick="logaop_warn"
android:layout_width="match_parent"/>
<Button android:layout_height="wrap_content"
android:text="logaop_error"
android:textAllCaps="false"
android:onClick="logaop_error"
android:layout_width="match_parent"/>
<Button android:layout_height="wrap_content"
android:text="logaop_throwable"
android:textAllCaps="false"
android:onClick="logaop_throwable"
android:layout_width="match_parent"/>


</LinearLayout>
Expand Down
3 changes: 2 additions & 1 deletion remote3.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ gradle.addProjectEvaluationListener(new ProjectEvaluationListener() {
'com.sensorsdata.analytics.android.sdk','io.reactivex','androidx.startup','com.chuckerteam.chucker.api.ChuckerInterceptor','com.hss01248.network.chucker',
'androidx.appcompat.app','io.flutter.plugins.webviewflutter','com.hss01248.aop.webview',
'com.sensorsdata.analytics.android','com.bumptech.glide.util.ByteBufferUtil',
'com.shizhefei.view.largeimage.factory','pl.droidsonroids.gif.InputSource'
'com.shizhefei.view.largeimage.factory','pl.droidsonroids.gif.InputSource',
'com.blankj.utilcode.util.LogUtils'
}
}else {
println("not apply aspectjx ,not add flipper networkinterceptor to okhttpclient automatically," +
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ include ':flipper-collector'
include ':flipper-leakcanary'
include ":aop-alert-dialog"
include ':aop-webview'
include ':aop-utilcode'

0 comments on commit 4fb866f

Please sign in to comment.