You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/app/log/access.go

39 lines
931 B

9 years ago
package log
import (
"v2ray.com/core/app/log/internal"
"v2ray.com/core/common/errors"
)
9 years ago
// AccessStatus is the status of an access request from clients.
9 years ago
type AccessStatus string
const (
AccessAccepted = AccessStatus("accepted")
AccessRejected = AccessStatus("rejected")
)
var (
9 years ago
accessLoggerInstance internal.LogWriter = new(internal.NoOpLogWriter)
)
9 years ago
9 years ago
// InitAccessLogger initializes the access logger to write into the give file.
func InitAccessLogger(file string) error {
9 years ago
logger, err := internal.NewFileLogWriter(file)
if err != nil {
return errors.New("failed to create access logger on file: ", file).Base(err).Path("App", "Log")
9 years ago
}
accessLoggerInstance = logger
return nil
9 years ago
}
9 years ago
// Access writes an access log.
func Access(from, to interface{}, status AccessStatus, reason interface{}) {
9 years ago
accessLoggerInstance.Log(&internal.AccessLog{
From: from,
To: to,
9 years ago
Status: string(status),
Reason: reason,
})
9 years ago
}