Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
gl_tape
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
3
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a0557323
authored
Sep 29, 2024
by
yixinjj
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
日志文件排队上传
1 parent
66959f50
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
23 deletions
utils/logger/LogCat.js
ws/Ws.js
ws/workers/LogsWorker.js
utils/logger/LogCat.js
View file @
a055732
...
@@ -33,7 +33,7 @@ class LogCat {
...
@@ -33,7 +33,7 @@ class LogCat {
path
.
mkdirs
()
//创建父路径
path
.
mkdirs
()
//创建父路径
}
}
let
fos
=
null
let
fos
=
null
let
bw
=
null
let
bw
=
null
try
{
try
{
fos
=
new
this
.
FileOutputStream
(
fileName
,
true
)
fos
=
new
this
.
FileOutputStream
(
fileName
,
true
)
bw
=
new
this
.
BufferedWriter
(
new
this
.
OutputStreamWriter
(
fos
))
bw
=
new
this
.
BufferedWriter
(
new
this
.
OutputStreamWriter
(
fos
))
...
...
ws/Ws.js
View file @
a055732
...
@@ -56,7 +56,7 @@ export class Ws {
...
@@ -56,7 +56,7 @@ export class Ws {
this
.
ws
.
on
(
WsTyps
.
Connected
,
()
=>
{
this
.
ws
.
on
(
WsTyps
.
Connected
,
()
=>
{
uni
.
$logger
.
local
.
info
(
'========WebSocket 连接成功========'
)
uni
.
$logger
.
local
.
info
(
'========WebSocket 连接成功========'
)
})
})
this
.
ws
.
on
(
this
.
ws
.
on
(
WsTyps
.
MessageTypes
.
Private
,
WsTyps
.
MessageTypes
.
Private
,
function
(
data
)
{
function
(
data
)
{
uni
.
$logger
.
local
.
info
(
`WebSocket 收到消息 ->
${
JSON
.
stringify
(
data
)}
`
)
uni
.
$logger
.
local
.
info
(
`WebSocket 收到消息 ->
${
JSON
.
stringify
(
data
)}
`
)
...
...
ws/workers/LogsWorker.js
View file @
a055732
...
@@ -4,38 +4,59 @@ export default class LogsWorker {
...
@@ -4,38 +4,59 @@ export default class LogsWorker {
logFile
=
null
logFile
=
null
constructor
()
{
constructor
()
{
this
.
logFile
=
uni
.
$logger
.
local
.
logger
this
.
logFile
=
uni
.
$logger
.
local
.
logger
this
.
isUploading
=
false
}
}
getLogFileList
()
{
getLogFileList
()
{
return
this
.
logFile
.
getLogFileList
()
return
this
.
logFile
.
getLogFileList
()
}
}
upload
(
deviceId
,
data
)
{
upload
(
deviceId
,
data
)
{
if
(
this
.
isUploading
)
{
const
msg
=
`日志上传中,请稍后再试!`
uni
.
$logger
.
local
.
info
(
msg
)
// this.ws.send(msg)
return
}
this
.
isUploading
=
true
const
files
=
this
.
getLogFileList
()
const
files
=
this
.
getLogFileList
()
this
.
process
(
files
,
deviceId
)
if
(
files
?.
length
)
{
files
.
sort
((
a
,
b
)
=>
a
.
name
.
localeCompare
(
b
.
name
))
this
.
process
(
files
,
deviceId
)
}
}
}
process
(
files
,
deviceId
)
{
async
process
(
files
,
deviceId
)
{
files
.
forEach
(
file
=>
this
.
post
(
file
,
deviceId
))
if
(
files
.
length
>
0
)
{
const
file
=
files
.
shift
()
await
this
.
post
(
file
,
deviceId
)
this
.
process
(
files
,
deviceId
)
}
else
{
this
.
isUploading
=
false
}
}
}
post
({
name
,
path
},
deviceId
)
{
post
({
name
,
path
},
deviceId
)
{
uni
.
uploadFile
({
return
new
Promise
((
resolve
,
reject
)
=>
{
url
:
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
HTTP_PORT
}
/
${
config
.
FILE_UPLOAD_URL
}
`
,
uni
.
uploadFile
({
filePath
:
path
,
url
:
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
HTTP_PORT
}
/
${
config
.
FILE_UPLOAD_URL
}
`
,
name
:
'file'
,
filePath
:
path
,
header
:
{
name
:
'file'
,
'Content-Type'
:
'multipart/form-data'
header
:
{
},
'Content-Type'
:
'multipart/form-data'
formData
:
{
},
deviceId
,
formData
:
{
type
:
'log'
deviceId
,
},
type
:
'log'
success
:
res
=>
{
},
uni
.
$logger
.
local
.
info
(
`文件上传成功! res->
${
serializeIfObject
(
res
)}
`
)
success
:
res
=>
{
},
uni
.
$logger
.
local
.
info
(
`文件上传成功! res->
${
serializeIfObject
(
res
)}
filePath->
${
path
}
`
)
fail
:
res
=>
{
resolve
()
uni
.
$logger
.
local
.
error
(
`文件上传失败! res->
${
serializeIfObject
(
res
)}
`
)
},
}
fail
:
res
=>
{
uni
.
$logger
.
local
.
error
(
`文件上传失败! res->
${
serializeIfObject
(
res
)}
filePath->
${
path
}
.请检查服务端是否有文件被打开`
)
resolve
()
}
})
})
})
}
}
work
(
deviceId
,
data
,
ws
)
{
work
(
deviceId
,
data
,
ws
)
{
this
.
ws
=
ws
this
.
ws
=
ws
this
.
upload
(
deviceId
,
data
)
this
.
upload
(
deviceId
,
data
)
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment