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:
Ludvig Lundgren 2022-07-05 13:31:44 +02:00 committed by GitHub
parent 95471a4cf7
commit 0e88117702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 1172 additions and 957 deletions

View file

@ -1,12 +1,10 @@
package download_client
import (
"fmt"
"time"
"github.com/pkg/errors"
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/autobrr/autobrr/pkg/lidarr"
"github.com/autobrr/autobrr/pkg/qbittorrent"
"github.com/autobrr/autobrr/pkg/radarr"
@ -48,6 +46,7 @@ func (s *service) testQbittorrentConnection(client domain.DownloadClient) error
Password: client.Password,
TLS: client.TLS,
TLSSkipVerify: client.TLSSkipVerify,
Log: s.subLogger,
}
// only set basic auth if enabled
@ -60,7 +59,7 @@ func (s *service) testQbittorrentConnection(client domain.DownloadClient) error
qbt := qbittorrent.NewClient(qbtSettings)
err := qbt.Login()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error logging into client: %v", client.Host))
return errors.Wrap(err, "error logging into client: %v", client.Host)
}
s.log.Debug().Msgf("test client connection for qBittorrent: success")
@ -94,7 +93,7 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error {
// perform connection to Deluge server
err := deluge.Connect()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error logging into client: %v", client.Host))
return errors.Wrap(err, "error logging into client: %v", client.Host)
}
defer deluge.Close()
@ -102,7 +101,7 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error {
// print daemon version
ver, err := deluge.DaemonVersion()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("could not get daemon version: %v", client.Host))
return errors.Wrap(err, "could not get daemon version: %v", client.Host)
}
s.log.Debug().Msgf("test client connection for Deluge: success - daemon version: %v", ver)
@ -117,11 +116,12 @@ func (s *service) testRadarrConnection(client domain.DownloadClient) error {
BasicAuth: client.Settings.Basic.Auth,
Username: client.Settings.Basic.Username,
Password: client.Settings.Basic.Password,
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("radarr: connection test failed: %v", client.Host))
return errors.Wrap(err, "radarr: connection test failed: %v", client.Host)
}
s.log.Debug().Msgf("test client connection for Radarr: success")
@ -136,11 +136,12 @@ func (s *service) testSonarrConnection(client domain.DownloadClient) error {
BasicAuth: client.Settings.Basic.Auth,
Username: client.Settings.Basic.Username,
Password: client.Settings.Basic.Password,
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("sonarr: connection test failed: %v", client.Host))
return errors.Wrap(err, "sonarr: connection test failed: %v", client.Host)
}
s.log.Debug().Msgf("test client connection for Sonarr: success")
@ -155,11 +156,12 @@ func (s *service) testLidarrConnection(client domain.DownloadClient) error {
BasicAuth: client.Settings.Basic.Auth,
Username: client.Settings.Basic.Username,
Password: client.Settings.Basic.Password,
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("lidarr: connection test failed: %v", client.Host))
return errors.Wrap(err, "lidarr: connection test failed: %v", client.Host)
}
s.log.Debug().Msgf("test client connection for Lidarr: success")
@ -174,11 +176,12 @@ func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
BasicAuth: client.Settings.Basic.Auth,
Username: client.Settings.Basic.Username,
Password: client.Settings.Basic.Password,
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("whisparr: connection test failed: %v", client.Host))
return errors.Wrap(err, "whisparr: connection test failed: %v", client.Host)
}
s.log.Debug().Msgf("test client connection for whisparr: success")