Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
0078b4c5
Commit
0078b4c5
authored
Apr 01, 2021
by
刘鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: api埋点完成,工具类迁移到net库
parent
8b9a99be
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
17 deletions
+31
-17
config.gradle
config.gradle
+3
-2
build.gradle
ydl-net/build.gradle
+1
-0
RequestLogInterceptor.java
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
+16
-13
AliYunLogConfig.kt
ydl-net/src/main/java/com/ydl/ydlnet/utils/log/AliYunLogConfig.kt
+10
-1
AliYunLogHelper.kt
ydl-net/src/main/java/com/ydl/ydlnet/utils/log/AliYunLogHelper.kt
+1
-1
No files found.
config.gradle
View file @
0078b4c5
...
...
@@ -44,7 +44,7 @@ ext {
//以下 几乎不会动
"router"
:
"0.0.1"
,
"ydl-net"
:
"0.0.3.
3
"
,
"ydl-net"
:
"0.0.3.
6
"
,
"ydl-utils"
:
"0.0.3.1"
,
]
ydl_app
=
[
...
...
@@ -126,7 +126,7 @@ ext {
//以下 几乎不会动
"router"
:
"0.0.1"
,
"ydl-net"
:
"0.0.3.
3
"
,
"ydl-net"
:
"0.0.3.
6
"
,
"ydl-utils"
:
"0.0.3.1"
,
]
...
...
@@ -199,6 +199,7 @@ ext {
"androideventbus"
:
"org.simple:androideventbus:1.0.5.1"
,
"otto"
:
"com.squareup:otto:1.3.8"
,
"gson"
:
"com.google.code.gson:gson:2.8.5"
,
"aliyun"
:
"com.aliyun.openservices:aliyun-log-android-sdk:2.5.13"
,
"javax.annotation"
:
"javax.annotation:jsr250-api:1.0"
,
"arouter"
:
"com.alibaba:arouter-api:1.4.1"
,
"progressmanager"
:
"me.jessyan:progressmanager:1.5.0"
,
...
...
ydl-net/build.gradle
View file @
0078b4c5
...
...
@@ -41,6 +41,7 @@ dependencies {
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
api
rootProject
.
ext
.
dependencies
[
"gson"
]
api
rootProject
.
ext
.
dependencies
[
"aliyun"
]
api
rootProject
.
ext
.
dependencies
[
"rxjava2"
]
api
(
rootProject
.
ext
.
dependencies
[
"rxandroid2"
])
{
exclude
module:
'rxjava'
...
...
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
View file @
0078b4c5
...
...
@@ -7,6 +7,8 @@ import com.ydl.ydlnet.utils.CharacterHandler;
import
com.ydl.ydlnet.utils.NetLogUtils
;
import
com.ydl.ydlnet.utils.UrlEncoderUtils
;
import
com.ydl.ydlnet.utils.ZipHelper
;
import
com.ydl.ydlnet.utils.log.AliYunLogConfig
;
import
com.ydl.ydlnet.utils.log.AliYunLogHelper
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
...
...
@@ -23,13 +25,14 @@ import okhttp3.Response;
import
okhttp3.ResponseBody
;
import
okio.Buffer
;
import
okio.BufferedSource
;
/**
* Created by haorui on 2019-09-01 .
* Des: 解析框架中的网络请求和响应结果并打印
*/
public
class
RequestLogInterceptor
implements
Interceptor
{
private
DefaultFormatPrinter
mPrinter
=
new
DefaultFormatPrinter
();
private
boolean
mIsDebug
;
private
boolean
mIsDebug
;
private
RequestHandler
mRequestHandler
;
public
RequestLogInterceptor
(
boolean
isDebug
,
RequestHandler
requestHandler
)
{
...
...
@@ -48,10 +51,10 @@ public class RequestLogInterceptor implements Interceptor {
mPrinter
.
printFileRequest
(
request
);
}
if
(
mRequestHandler
!=
null
)
if
(
mRequestHandler
!=
null
)
{
request
=
mRequestHandler
.
onHttpRequestBefore
(
chain
,
request
);
long
t1
=
System
.
nanoTime
()
;
}
long
t1
=
System
.
nanoTime
()
;
Response
originalResponse
;
try
{
originalResponse
=
chain
.
proceed
(
request
);
...
...
@@ -59,7 +62,7 @@ public class RequestLogInterceptor implements Interceptor {
NetLogUtils
.
debugInfo
(
"Http Error: "
+
e
);
throw
e
;
}
long
t2
=
System
.
nanoTime
()
;
long
t2
=
System
.
nanoTime
();
ResponseBody
responseBody
=
originalResponse
.
body
();
...
...
@@ -67,12 +70,12 @@ public class RequestLogInterceptor implements Interceptor {
String
bodyString
=
null
;
if
(
responseBody
!=
null
&&
isParseable
(
responseBody
.
contentType
()))
{
bodyString
=
printResult
(
request
,
originalResponse
);
if
(
mRequestHandler
!=
null
){
if
(
mRequestHandler
!=
null
)
{
mRequestHandler
.
onHttpResultResponse
(
bodyString
,
chain
,
originalResponse
);
}
}
if
(
mIsDebug
)
{
if
(
mIsDebug
)
{
final
List
<
String
>
segmentList
=
request
.
url
().
encodedPathSegments
();
final
String
header
=
originalResponse
.
headers
().
toString
();
final
int
code
=
originalResponse
.
code
();
...
...
@@ -87,20 +90,20 @@ public class RequestLogInterceptor implements Interceptor {
mPrinter
.
printFileResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
segmentList
,
message
,
url
);
}
}
else
{
}
else
{
int
code
=
originalResponse
.
code
();
// 接口返回错误的情况下,埋点告诉服务器原因
if
(
code
!=
200
)
{
if
(
code
!=
200
)
{
String
params
=
""
;
Request
rq
=
originalResponse
.
request
();
if
(
rq
.
method
().
equals
(
"GET"
)){
if
(
rq
.
method
().
equals
(
"GET"
))
{
params
=
rq
.
url
().
query
();
}
else
if
(
rq
.
method
().
equals
(
"POST"
))
{
}
else
if
(
rq
.
method
().
equals
(
"POST"
))
{
params
=
parseParams
(
rq
);
}
String
message
=
originalResponse
.
message
();
ApiErrorCountUtils
.
Companion
.
baiDuCount
(
"pardId-ydl_user_error_business"
,
"error_log"
,
params
,
message
);
ApiErrorCountUtils
.
Companion
.
baiDuCount
(
"pardId-ydl_user_error_business"
,
"error_log"
,
params
,
message
);
AliYunLogHelper
.
Companion
.
getInstance
().
sendLog
(
AliYunLogConfig
.
API
,
"error_log--- params:"
+
params
+
" ---- message:"
+
message
);
}
}
return
originalResponse
;
...
...
ydl-
platform/src/main/java/com/ydl/ydlcommon
/utils/log/AliYunLogConfig.kt
→
ydl-
net/src/main/java/com/ydl/ydlnet
/utils/log/AliYunLogConfig.kt
View file @
0078b4c5
package
com.ydl.ydl
common
.utils.log
package
com.ydl.ydl
net
.utils.log
object
AliYunLogConfig
{
/**接口*/
...
...
@@ -16,6 +16,15 @@ object AliYunLogConfig {
/**支付*/
const
val
PAY
=
"Pay"
/**云信*/
const
val
YUNXIN
=
"YunXin"
/**RTM*/
const
val
RTM
=
"Rtm"
/**网络状态*/
const
val
NETSTATUS
=
"NetStatus"
/**其他*/
const
val
OTHER
=
"Other"
...
...
ydl-
platform/src/main/java/com/ydl/ydlcommon
/utils/log/AliYunLogHelper.kt
→
ydl-
net/src/main/java/com/ydl/ydlnet
/utils/log/AliYunLogHelper.kt
View file @
0078b4c5
package
com.ydl.ydl
common
.utils.log
package
com.ydl.ydl
net
.utils.log
import
android.util.Log
import
com.aliyun.sls.android.producer.*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment