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/common/log/access.go

46 lines
1005 B

9 years ago
package log
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 (
accessLoggerInstance logWriter = &noOpLogWriter{}
)
9 years ago
type accessLog struct {
From string
To string
Status AccessStatus
Reason string
}
func (this *accessLog) String() string {
return this.From + " " + string(this.Status) + " " + this.To + " " + this.Reason
9 years ago
}
9 years ago
// InitAccessLogger initializes the access logger to write into the give file.
func InitAccessLogger(file string) error {
logger, err := newFileLogWriter(file)
if err != nil {
Error("Failed to create access logger on file (", file, "): ", file, err)
return err
9 years ago
}
accessLoggerInstance = logger
return nil
9 years ago
}
9 years ago
// Access writes an access log.
9 years ago
func Access(from, to string, status AccessStatus, reason string) {
accessLoggerInstance.Log(&accessLog{
From: from,
To: to,
Status: status,
Reason: reason,
})
9 years ago
}