1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 03:37:37 -05:00
v2fly/common/log/access.go
2016-05-11 23:24:41 -07:00

40 lines
954 B
Go

package log
import (
"github.com/v2ray/v2ray-core/common/log/internal"
"github.com/v2ray/v2ray-core/common/serial"
)
// 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 {
Error("Failed to create access logger on file (", file, "): ", file, err)
return err
}
accessLoggerInstance = logger
return nil
}
// Access writes an access log.
func Access(from, to serial.String, status AccessStatus, reason serial.String) {
accessLoggerInstance.Log(&internal.AccessLog{
From: from,
To: to,
Status: string(status),
Reason: reason,
})
}