From 627eae999b7e82fe22058b687df261973f81ec4c Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 16 Jun 2017 13:48:11 +0200 Subject: [PATCH] Improved avatar log --- jobs/avatars/Avatar.go | 8 +++++--- jobs/avatars/Gravatar.go | 4 +++- jobs/avatars/MyAnimeList.go | 9 +++++---- jobs/avatars/main.go | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/jobs/avatars/Avatar.go b/jobs/avatars/Avatar.go index 21f19343..25c5b21a 100644 --- a/jobs/avatars/Avatar.go +++ b/jobs/avatars/Avatar.go @@ -11,6 +11,8 @@ import ( "github.com/parnurzeal/gorequest" ) +var netLog = avatarLog.NewChannel("NET") + // Avatar represents a single image and the name of the format. type Avatar struct { User *arn.User @@ -37,13 +39,13 @@ func AvatarFromURL(url string, user *arn.User) *Avatar { // Network errors if networkErr != nil { - avatarLog.Error("NET", user.Nick, url, networkErr) + netLog.Error(user.Nick, url, networkErr) return nil } // Bad status codes if response.StatusCode != http.StatusOK { - avatarLog.Error("NET", user.Nick, url, response.StatusCode) + netLog.Error(user.Nick, url, response.StatusCode) return nil } @@ -51,7 +53,7 @@ func AvatarFromURL(url string, user *arn.User) *Avatar { img, format, decodeErr := image.Decode(bytes.NewReader(data)) if decodeErr != nil { - avatarLog.Error("IMG", user.Nick, url, decodeErr) + netLog.Error(user.Nick, url, decodeErr) return nil } diff --git a/jobs/avatars/Gravatar.go b/jobs/avatars/Gravatar.go index 44c3fbaa..2ec685ce 100644 --- a/jobs/avatars/Gravatar.go +++ b/jobs/avatars/Gravatar.go @@ -8,6 +8,8 @@ import ( gravatar "github.com/ungerik/go-gravatar" ) +var gravatarLog = avatarLog.NewChannel("GRA") + // Gravatar - https://gravatar.com/ type Gravatar struct { Rating string @@ -18,7 +20,7 @@ type Gravatar struct { func (source *Gravatar) GetAvatar(user *arn.User) *Avatar { // If the user has no Email registered we can't get a Gravatar. if user.Email == "" { - avatarLog.Error("GRA", user.Nick, "No Email") + gravatarLog.Error(user.Nick, "No Email") return nil } diff --git a/jobs/avatars/MyAnimeList.go b/jobs/avatars/MyAnimeList.go index d38f6e0a..e1a30b52 100644 --- a/jobs/avatars/MyAnimeList.go +++ b/jobs/avatars/MyAnimeList.go @@ -10,6 +10,7 @@ import ( ) var userIDRegex = regexp.MustCompile(`(\d+)<\/user_id>`) +var malLog = avatarLog.NewChannel("MAL") // MyAnimeList - https://myanimelist.net/ type MyAnimeList struct { @@ -22,7 +23,7 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar { // If the user has no username we can't get an avatar. if malNick == "" { - avatarLog.Error("MAL", user.Nick, "No MAL nick") + malLog.Error(user.Nick, "No MAL nick") return nil } @@ -31,12 +32,12 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar { response, xml, networkErr := gorequest.New().Get(userInfoURL).End() if networkErr != nil { - avatarLog.Error("MAL", user.Nick, userInfoURL, networkErr) + malLog.Error(user.Nick, userInfoURL, networkErr) return nil } if response.StatusCode != http.StatusOK { - avatarLog.Error("MAL", user.Nick, userInfoURL, response.StatusCode) + malLog.Error(user.Nick, userInfoURL, response.StatusCode) return nil } @@ -44,7 +45,7 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar { matches := userIDRegex.FindStringSubmatch(xml) if matches == nil || len(matches) < 2 { - avatarLog.Error("MAL", user.Nick, "Could not find user ID") + malLog.Error(user.Nick, "Could not find user ID") return nil } diff --git a/jobs/avatars/main.go b/jobs/avatars/main.go index 1f89a1f6..101b122e 100644 --- a/jobs/avatars/main.go +++ b/jobs/avatars/main.go @@ -22,7 +22,7 @@ const ( var avatarSources []AvatarSource var avatarOutputs []AvatarOutput -var avatarLog = log.NewChannel("avatar") +var avatarLog = log.NewLog() // Main func main() {