access.go 905 B

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