Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
go-api-behavior
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e8bcd614
authored
Mar 24, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
init
parent
89913c2e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
5 deletions
README.md
service/behavior/apiMsgService/LogSink.go
service/behavior/main.go
util/config.go
README.md
View file @
e8bcd614
...
...
@@ -12,6 +12,7 @@
"access_url":"api.ichun.com/v3/login",
"err_msg":"响应超时",
"err_code":"40004",
"request_params":"tttttttttt",
"uid":"16678",
"user_name":"张三",
"user_ip":"153.2.15.1",
...
...
service/behavior/apiMsgService/LogSink.go
View file @
e8bcd614
...
...
@@ -62,7 +62,7 @@ func (logSink *LogSink) writeLoop() {
}
// 把新日志追加到批次中
logBatch
.
Logs
=
append
(
logBatch
.
Logs
,
log
)
logBatch
.
Logs
=
append
(
logBatch
.
Logs
,
*
log
)
// 如果批次满了, 就立即发送
if
len
(
logBatch
.
Logs
)
>=
int
(
util
.
Configs
.
LogSaveConfig
.
Length
)
{
// 发送日志
...
...
@@ -78,7 +78,7 @@ func (logSink *LogSink) writeLoop() {
//fmt.Println(len(logBatch.Logs))
logSink
.
saveLogs
(
logBatch
)
logBatch
=
nil
t
.
Reset
(
time
.
Second
*
20
)
t
.
Reset
(
time
.
Second
*
sleepTime
)
}
...
...
@@ -100,7 +100,7 @@ func InitLogSink() (err error) {
// 选择db和collection
G_logSink
=
&
LogSink
{
client
:
client
,
logCollection
:
client
.
Database
(
"monitor"
)
.
Collection
(
"monitor_log"
),
logCollection
:
client
.
Database
(
util
.
Configs
.
Mongodb_databases
.
Databases
)
.
Collection
(
util
.
Configs
.
Mongodb_databases
.
Collection
),
logChan
:
make
(
chan
*
DataParams
,
1000
),
//autoCommitChan: make(chan *common.LogBatch, 1000),
}
...
...
service/behavior/main.go
View file @
e8bcd614
...
...
@@ -87,7 +87,7 @@ func main() {
for
{
var
wg
sync
.
WaitGroup
fmt
.
Println
(
"开始执行任务...."
)
//
fmt.Println("开始执行任务....")
for
i
:=
0
;
i
<
3
;
i
++
{
wg
.
Add
(
1
)
go
func
(
wg
*
sync
.
WaitGroup
){
...
...
@@ -102,7 +102,7 @@ func main() {
}(
&
wg
)
}
wg
.
Wait
()
fmt
.
Println
(
"执行任务完成...."
)
//
fmt.Println("执行任务完成....")
time
.
Sleep
(
time
.
Microsecond
*
10
)
}
}
\ No newline at end of file
util/config.go
View file @
e8bcd614
...
...
@@ -31,6 +31,8 @@ type RabbitmqIchunt struct {
type
MongodbDatabases
struct
{
Dns
string
`toml:"dns"`
Databases
string
`toml:"databases"`
Collection
string
`toml:"collection"`
}
type
LogSaveConfigs
struct
{
...
...
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