mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(logging); improve messages and errors (#336)
* feat(logger): add module context * feat(logger): change errors package * feat(logger): update tests
This commit is contained in:
parent
95471a4cf7
commit
0e88117702
69 changed files with 1172 additions and 957 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/internal/logger"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -63,7 +64,7 @@ func Test_service_parseExecArgs(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &service{
|
||||
log: logger.Mock(),
|
||||
log: logger.Mock().With().Logger(),
|
||||
repo: nil,
|
||||
clientSvc: nil,
|
||||
bus: nil,
|
||||
|
@ -102,7 +103,7 @@ func Test_service_execCmd(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &service{
|
||||
log: logger.Mock(),
|
||||
log: logger.Mock().With().Logger(),
|
||||
repo: nil,
|
||||
clientSvc: nil,
|
||||
bus: nil,
|
||||
|
|
|
@ -30,6 +30,7 @@ func (s *service) lidarr(release domain.Release, action domain.Action) ([]string
|
|||
cfg := lidarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
Log: s.subLogger,
|
||||
}
|
||||
|
||||
// only set basic auth if enabled
|
||||
|
|
|
@ -56,10 +56,10 @@ func (s *service) qbittorrent(qbt *qbittorrent.Client, action domain.Action, rel
|
|||
options["tags"] = tagsArgs
|
||||
}
|
||||
if action.LimitUploadSpeed > 0 {
|
||||
options["upLimit"] = strconv.FormatInt(action.LimitUploadSpeed * 1000, 10)
|
||||
options["upLimit"] = strconv.FormatInt(action.LimitUploadSpeed*1000, 10)
|
||||
}
|
||||
if action.LimitDownloadSpeed > 0 {
|
||||
options["dlLimit"] = strconv.FormatInt(action.LimitDownloadSpeed * 1000, 10)
|
||||
options["dlLimit"] = strconv.FormatInt(action.LimitDownloadSpeed*1000, 10)
|
||||
}
|
||||
if action.LimitRatio > 0 {
|
||||
options["ratioLimit"] = strconv.FormatFloat(action.LimitRatio, 'r', 2, 64)
|
||||
|
@ -109,6 +109,7 @@ func (s *service) qbittorrentCheckRulesCanDownload(action domain.Action) (bool,
|
|||
Password: client.Password,
|
||||
TLS: client.TLS,
|
||||
TLSSkipVerify: client.TLSSkipVerify,
|
||||
Log: s.subLogger,
|
||||
}
|
||||
|
||||
// only set basic auth if enabled
|
||||
|
|
|
@ -29,6 +29,7 @@ func (s *service) radarr(release domain.Release, action domain.Action) ([]string
|
|||
cfg := radarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
Log: s.subLogger,
|
||||
}
|
||||
|
||||
// only set basic auth if enabled
|
||||
|
|
|
@ -2,12 +2,15 @@ package action
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/asaskevich/EventBus"
|
||||
"log"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/internal/download_client"
|
||||
"github.com/autobrr/autobrr/internal/logger"
|
||||
|
||||
"github.com/asaskevich/EventBus"
|
||||
"github.com/dcarbone/zadapters/zstdlog"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
|
@ -22,19 +25,24 @@ type Service interface {
|
|||
}
|
||||
|
||||
type service struct {
|
||||
log logger.Logger
|
||||
log zerolog.Logger
|
||||
subLogger *log.Logger
|
||||
repo domain.ActionRepo
|
||||
clientSvc download_client.Service
|
||||
bus EventBus.Bus
|
||||
}
|
||||
|
||||
func NewService(log logger.Logger, repo domain.ActionRepo, clientSvc download_client.Service, bus EventBus.Bus) Service {
|
||||
return &service{
|
||||
log: log,
|
||||
s := &service{
|
||||
log: log.With().Str("module", "action").Logger(),
|
||||
repo: repo,
|
||||
clientSvc: clientSvc,
|
||||
bus: bus,
|
||||
}
|
||||
|
||||
s.subLogger = zstdlog.NewStdLoggerWithLevel(s.log.With().Logger(), zerolog.TraceLevel)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *service) Store(ctx context.Context, action domain.Action) (*domain.Action, error) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
"github.com/autobrr/autobrr/pkg/sonarr"
|
||||
)
|
||||
|
||||
|
@ -17,18 +18,19 @@ func (s *service) sonarr(release domain.Release, action domain.Action) ([]string
|
|||
client, err := s.clientSvc.FindByID(context.TODO(), action.ClientID)
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Msgf("sonarr: error finding client: %v", action.ClientID)
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "sonarr could not find client: %v", action.ClientID)
|
||||
}
|
||||
|
||||
// return early if no client found
|
||||
if client == nil {
|
||||
return nil, err
|
||||
return nil, errors.New("no client found")
|
||||
}
|
||||
|
||||
// initial config
|
||||
cfg := sonarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
Log: s.subLogger,
|
||||
}
|
||||
|
||||
// only set basic auth if enabled
|
||||
|
|
|
@ -29,6 +29,7 @@ func (s *service) whisparr(release domain.Release, action domain.Action) ([]stri
|
|||
cfg := whisparr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
Log: s.subLogger,
|
||||
}
|
||||
|
||||
// only set basic auth if enabled
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue