-
Notifications
You must be signed in to change notification settings - Fork 6
/
async.go
39 lines (34 loc) · 1003 Bytes
/
async.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2020 HigKer
// Open Source: MIT License
// Author: SDing <deen.job@qq.com>
// Date: 2020/5/1 - 12:53 上午
package logker
const (
// Log message format wildcards
// {level} == logging level
// {time} == time
// {position} == runtime caller info
// {message} == logging message
// This was modified for v 1.1.5
// OutPut: [INFO] 2006-01-02 13:05.0006 MP - Position: test.go|main.test:21 - Message: news
DefaultFormat = "{level} - Date: {time} {position} - Message: {message}"
)
// Asynchronous Task Interface
// added after v1.1.6
type Async interface {
sendMsg(msg *message)
begin()
}
// Asynchronous Task Processing
type AsyncTask struct {
queueSize int64
logQueue chan *message
sync chan bool
}
// Initializes The Logging Producer Channel Buffer
// Queue Size Data Type int64
func InitAsync(queueSize int64) *AsyncTask {
at := &AsyncTask{queueSize: queueSize, logQueue: make(chan *message, queueSize), sync:make(chan bool, 1)}
at.sync <- true
return at
}