feat: add watcher and logger

This commit is contained in:
weloe
2023-05-05 04:16:21 +08:00
parent a5652cd390
commit 7355e1c107
4 changed files with 126 additions and 0 deletions

71
log/default_logger.go Normal file
View File

@@ -0,0 +1,71 @@
package log
import (
"github.com/weloe/token-go/model"
"log"
)
var _ Logger = (*DefaultLogger)(nil)
type DefaultLogger struct {
enable bool
}
func (d *DefaultLogger) Enable(bool bool) {
d.enable = bool
}
func (d *DefaultLogger) IsEnabled() bool {
return d.enable
}
func (d *DefaultLogger) Login(loginType string, id interface{}, tokenValue string, loginModel *model.Login) {
if !d.enable {
return
}
log.Printf("LoginByModel: loginId = %v, loginType = %v, tokenValue = %v, "+
"loginMode = %v", id, loginType, tokenValue, loginModel)
}
func (d *DefaultLogger) Logout(loginType string, id interface{}, tokenValue string) {
if !d.enable {
return
}
log.Printf("Logout: loginId = %v, loginType = %v, tokenValue = %v", id, loginType, tokenValue)
}
func (d *DefaultLogger) Kickout(loginType string, id interface{}, tokenValue string) {
if !d.enable {
return
}
log.Printf("Kickout: loginId = %v, loginType = %v, tokenValue = %v", id, loginType, tokenValue)
}
func (d *DefaultLogger) Replace(loginType string, id interface{}, tokenValue string) {
if !d.enable {
return
}
log.Printf("Replaced: loginId = %v, loginType = %v, tokenValue = %v", id, loginType, tokenValue)
}
func (d *DefaultLogger) Ban(loginType string, id interface{}, service string) {
if !d.enable {
return
}
log.Printf("Banned: loginId = %v, loginType = %v, service = %v", id, loginType, service)
}
func (d *DefaultLogger) UnBan(loginType string, id interface{}, service string) {
if !d.enable {
return
}
log.Printf("UnBanned: loginId = %v, loginType = %v, service = %v", id, loginType, service)
}
func (d *DefaultLogger) RefreshToken(tokenValue string, id interface{}, timeout int64) {
if !d.enable {
return
}
log.Printf("RefreshToken: loginId = %v, tokenValue = %v, timeout = %v", id, tokenValue, timeout)
}