authlogger.go 642 B

12345678910111213141516171819202122232425262728293031
  1. package authlogger
  2. import (
  3. "log"
  4. "net/http"
  5. "time"
  6. )
  7. /*
  8. AuthLogger
  9. Author: tobychui
  10. This module help log the login request and help the user to trace who is trying
  11. to break into their system.
  12. */
  13. type Logger struct {
  14. }
  15. //New Logger create a new logger object
  16. func NewLogger() *Logger {
  17. return &Logger{}
  18. }
  19. //Log the current authentication to record, Require the request object and login status
  20. func (l *Logger) LogAuth(r *http.Request, loginStatus bool) {
  21. username, _ := mv(r, "username", true)
  22. timestamp := time.Now().Unix()
  23. log.Println("Logger log (timestamp, username, login succeed)", timestamp, username, loginStatus)
  24. }