| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package notify
- import (
- "time"
- "github.com/labring/aiproxy/core/common/config"
- "github.com/labring/aiproxy/core/common/trylock"
- log "github.com/sirupsen/logrus"
- )
- type StdNotifier struct{}
- var (
- infoLogrus = log.WithField("notify", "std")
- warnLogrus = log.WithField("notify", "std")
- errorLogrus = log.WithField("notify", "std")
- )
- func (n *StdNotifier) Notify(level Level, title, message string) {
- note := config.GetNotifyNote()
- switch level {
- case LevelInfo:
- logrus := infoLogrus.WithField("title", title)
- if note != "" {
- logrus = logrus.WithField("note", note)
- }
- logrus.Info(message)
- case LevelWarn:
- logrus := warnLogrus.WithField("title", title)
- if note != "" {
- logrus = logrus.WithField("note", note)
- }
- logrus.Warn(message)
- case LevelError:
- logrus := errorLogrus.WithField("title", title)
- if note != "" {
- logrus = logrus.WithField("note", note)
- }
- logrus.Error(message)
- }
- }
- func (n *StdNotifier) NotifyThrottle(
- level Level,
- key string,
- expiration time.Duration,
- title, message string,
- ) {
- if !trylock.MemLock(key, expiration) {
- return
- }
- n.Notify(level, title, message)
- }
|