migrated from logrus to zerolog, improved error formatting, fixed concurrent map write, fixed crash on rapid page refresh for idle containers, fixed infinite recursion on gotfiy error, fixed websocket connection problem when using idlewatcher

This commit is contained in:
yusing
2024-10-29 11:34:58 +08:00
parent cfa74d69ae
commit e5bbb18414
137 changed files with 2640 additions and 2348 deletions

View File

@@ -9,7 +9,7 @@ import (
"net/url"
"github.com/gotify/server/v2/model"
"github.com/sirupsen/logrus"
"github.com/rs/zerolog"
E "github.com/yusing/go-proxy/internal/error"
U "github.com/yusing/go-proxy/internal/utils"
)
@@ -39,7 +39,7 @@ func newGotifyClient(cfg map[string]any) (Provider, E.Error) {
url, uErr := url.Parse(client.URL)
if uErr != nil {
return nil, E.FailWith("parse url", uErr)
return nil, E.Errorf("invalid gotify URL %s", client.URL)
}
client.url = url
@@ -52,30 +52,23 @@ func (client *GotifyClient) Name() string {
}
// Send implements NotifProvider.
func (client *GotifyClient) Send(ctx context.Context, entry *logrus.Entry) error {
func (client *GotifyClient) Send(ctx context.Context, logMsg *LogMessage) error {
var priority int
var title string
switch entry.Level {
case logrus.WarnLevel:
switch logMsg.Level {
case zerolog.WarnLevel:
priority = 2
title = "Warning"
case logrus.ErrorLevel:
case zerolog.ErrorLevel:
priority = 5
title = "Error"
case logrus.FatalLevel, logrus.PanicLevel:
case zerolog.FatalLevel, zerolog.PanicLevel:
priority = 8
title = "Critical"
default:
return nil
}
if subjects := FieldsAsTitle(entry); subjects != "" {
title = subjects + " " + title
}
msg := &GotifyMessage{
Title: title,
Message: entry.Message,
Title: logMsg.Title,
Message: logMsg.Message,
Priority: priority,
}