access.go 931 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package log
  2. import (
  3. "v2ray.com/core/app/log/internal"
  4. "v2ray.com/core/common/errors"
  5. )
  6. // AccessStatus is the status of an access request from clients.
  7. type AccessStatus string
  8. const (
  9. AccessAccepted = AccessStatus("accepted")
  10. AccessRejected = AccessStatus("rejected")
  11. )
  12. var (
  13. accessLoggerInstance internal.LogWriter = new(internal.NoOpLogWriter)
  14. )
  15. // InitAccessLogger initializes the access logger to write into the give file.
  16. func InitAccessLogger(file string) error {
  17. logger, err := internal.NewFileLogWriter(file)
  18. if err != nil {
  19. return errors.New("Failed to create access logger on file: ", file).Base(err).Path("App", "Log")
  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. }