Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
qianhe-ydsj
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangyun
qianhe-ydsj
Commits
8d46c2f0
Commit
8d46c2f0
authored
Jan 29, 2026
by
jiang'yun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志服务
parent
794b2c11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
0 deletions
+134
-0
qianhe-admin/src/main/resources/application.yml
+5
-0
qianhe-ydsj/src/main/java/com/qianhe/util/LogUtil.java
+129
-0
No files found.
qianhe-admin/src/main/resources/application.yml
View file @
8d46c2f0
...
...
@@ -137,3 +137,8 @@ xss:
excludes
:
/system/notice,/system/wzgl,/system/bmjj,/system/wzgl/addxw
# 匹配链接
urlPatterns
:
/system/*,/monitor/*,/tool/*
# 日志
Log_appname
:
APP_SLYT_SJGLXT
Log_caKey
:
ee8d6cdbda2548f391a4b9389718abf7
Log_TransferUrl
:
http://api.ssco.sinopec.com/PUBService.log.transferLogs?appname=APP_SLYT_SJGLXT
qianhe-ydsj/src/main/java/com/qianhe/util/LogUtil.java
0 → 100644
View file @
8d46c2f0
package
com
.
qianhe
.
util
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.qianhe.common.utils.ip.IpUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.InetAddress
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
public
class
LogUtil
{
@Value
(
"${Log_caKey}"
)
private
String
Key
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
//发送日志请求
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
"John"
);
map
.
put
(
"age"
,
30
);
map
.
put
(
"isStudent"
,
false
);
JsonObject
jsonObject
=
sendSysLog
(
"LoginLog"
,
map
);
//获取日志
JsonObject
sysLog
=
getSysLog
();
}
/**
* 发送日志请求
* @param tag 日志类型(LoginLog、UserOpeLog、ErrorLog、IServiceLog、ComponentOpeLog、DBOpeLog、BusinessLog)
* @param map 日志内容
*/
public
static
JsonObject
sendSysLog
(
String
tag
,
Map
<
String
,
Object
>
map
)
throws
Exception
{
//本地ip
String
ip
=
IpUtils
.
getHostIp
();
//客户端ip
// String ip = IpUtils.getIpAddr();
String
url
=
"http://api.ssco.sinopec.com/PUBService.log.transferLogs?appname=APP_SLYT_SJGLXT&tag="
+
tag
+
"&hostname="
+
ip
;
Gson
gson
=
new
Gson
();
String
input
=
gson
.
toJson
(
map
);
URL
targetUrl
=
new
URL
(
url
);
HttpURLConnection
httpConnection
=
(
HttpURLConnection
)
targetUrl
.
openConnection
();
httpConnection
.
setDoOutput
(
true
);
httpConnection
.
setRequestMethod
(
"POST"
);
httpConnection
.
setRequestProperty
(
"Content-Type"
,
"application/json; charset=UTF-8;"
);
httpConnection
.
setRequestProperty
(
"X-Ca-API-Key"
,
"ee8d6cdbda2548f391a4b9389718abf7"
);
OutputStream
outputStream
=
httpConnection
.
getOutputStream
();
outputStream
.
write
(
input
.
getBytes
(
"UTF-8"
));
outputStream
.
flush
();
if
(
httpConnection
.
getResponseCode
()
!=
200
)
{
throw
new
RuntimeException
(
"Failed : HTTP error code : "
+
httpConnection
.
getResponseCode
());
}
InputStream
inputStream
=
httpConnection
.
getInputStream
();
ByteArrayOutputStream
buffer
=
new
ByteArrayOutputStream
();
byte
[]
data
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
data
,
0
,
data
.
length
))
!=
-
1
)
{
buffer
.
write
(
data
,
0
,
bytesRead
);
}
buffer
.
flush
();
byte
[]
binaryData
=
buffer
.
toByteArray
();
// 将二进制数据转换为字符串(假设是 UTF-8 编码的 JSON)
String
jsonString
=
new
String
(
binaryData
,
"UTF-8"
);
// 使用 Gson 解析 JSON 字符串
JsonObject
jsonObject
=
JsonParser
.
parseString
(
jsonString
).
getAsJsonObject
();
System
.
out
.
println
(
jsonObject
);
httpConnection
.
disconnect
();
return
jsonObject
;
}
/**
* 获取日志
*/
public
static
JsonObject
getSysLog
()
throws
Exception
{
String
apiUrl
=
"http://api.ssco.sinopec.com/api/v2/search/sheets/"
;
String
query
=
"appname:APP_SLYT_SJGLXT"
;
String
timeRange
=
"-1h,now"
;
boolean
timeline
=
false
;
String
searchMode
=
"simple"
;
String
url
=
apiUrl
+
"?query="
+
query
+
"&time_range="
+
timeRange
+
"&timeline="
+
timeline
+
"&searchMode="
+
searchMode
;
URL
targetUrl
=
new
URL
(
url
);
HttpURLConnection
httpConnection
=
(
HttpURLConnection
)
targetUrl
.
openConnection
();
httpConnection
.
setRequestMethod
(
"GET"
);
httpConnection
.
setRequestProperty
(
"X-Ca-API-Key"
,
"ee8d6cdbda2548f391a4b9389718abf7"
);
httpConnection
.
setRequestProperty
(
"Authorization"
,
"apikey lih2365:OYeEzLnOZiSPTNlKouAgeEQuTsokAvLA"
);
if
(
httpConnection
.
getResponseCode
()
!=
200
)
{
throw
new
RuntimeException
(
"Failed : HTTP error code : "
+
httpConnection
.
getResponseCode
());
}
InputStream
inputStream
=
httpConnection
.
getInputStream
();
ByteArrayOutputStream
buffer
=
new
ByteArrayOutputStream
();
byte
[]
data
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
data
,
0
,
data
.
length
))
!=
-
1
)
{
buffer
.
write
(
data
,
0
,
bytesRead
);
}
buffer
.
flush
();
byte
[]
binaryData
=
buffer
.
toByteArray
();
// 将二进制数据转换为字符串(假设是 UTF-8 编码的 JSON)
String
jsonString
=
new
String
(
binaryData
,
"UTF-8"
);
// 使用 Gson 解析 JSON 字符串
JsonObject
jsonObject
=
JsonParser
.
parseString
(
jsonString
).
getAsJsonObject
();
httpConnection
.
disconnect
();
return
jsonObject
;
}
}
\ No newline at end of file
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