access.go 873 B

1234567891011121314151617181920212223242526272829303132333435
  1. package log
  2. import "v2ray.com/core/app/log/internal"
  3. // AccessStatus is the status of an access request from clients.
  4. type AccessStatus string
  5. const (
  6. AccessAccepted = AccessStatus("accepted")
  7. AccessRejected = AccessStatus("rejected")
  8. )
  9. var (
  10. accessLoggerInstance internal.LogWriter = new(internal.NoOpLogWriter)
  11. )
  12. // InitAccessLogger initializes the access logger to write into the give file.
  13. func InitAccessLogger(file string) error {
  14. logger, err := internal.NewFileLogWriter(file)
  15. if err != nil {
  16. return newError("failed to create access logger on file: ", file).Base(err)
  17. }
  18. accessLoggerInstance = logger
  19. return nil
  20. }
  21. // Access writes an access log.
  22. func Access(from, to interface{}, status AccessStatus, reason interface{}) {
  23. accessLoggerInstance.Log(&internal.AccessLog{
  24. From: from,
  25. To: to,
  26. Status: string(status),
  27. Reason: reason,
  28. })
  29. }