-
Notifications
You must be signed in to change notification settings - Fork 0
/
access.go
35 lines (29 loc) · 873 Bytes
/
access.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
package log
import "v2ray.com/core/app/log/internal"
// AccessStatus is the status of an access request from clients.
type AccessStatus string
const (
AccessAccepted = AccessStatus("accepted")
AccessRejected = AccessStatus("rejected")
)
var (
accessLoggerInstance internal.LogWriter = new(internal.NoOpLogWriter)
)
// InitAccessLogger initializes the access logger to write into the give file.
func InitAccessLogger(file string) error {
logger, err := internal.NewFileLogWriter(file)
if err != nil {
return newError("failed to create access logger on file: ", file).Base(err)
}
accessLoggerInstance = logger
return nil
}
// Access writes an access log.
func Access(from, to interface{}, status AccessStatus, reason interface{}) {
accessLoggerInstance.Log(&internal.AccessLog{
From: from,
To: to,
Status: string(status),
Reason: reason,
})
}