From 1fd41ca503c6dba3cf5764fecd972d069f10beb1 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 8 Apr 2016 18:11:36 +0800 Subject: [PATCH] support android push log. Signed-off-by: Bo-Yi Wu --- gorush/log.go | 2 +- gorush/notification.go | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gorush/log.go b/gorush/log.go index ad07a40..e614045 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -150,7 +150,7 @@ func colorForPlatForm(platform int) string { case PlatFormIos: return blue case PlatFormAndroid: - return cyan + return yellow default: return reset } diff --git a/gorush/notification.go b/gorush/notification.go index 6619bd9..a0e514f 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -2,11 +2,11 @@ package gopush import ( "errors" + "fmt" "github.com/google/go-gcm" apns "github.com/sideshow/apns2" "github.com/sideshow/apns2/certificate" "github.com/sideshow/apns2/payload" - "log" ) type ExtendJSON struct { @@ -96,7 +96,7 @@ func InitAPNSClient() error { CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemKeyPath, "") if err != nil { - log.Println("Cert Error:", err) + LogError.Error("Cert Error:", err.Error()) return err } @@ -310,22 +310,22 @@ func PushToAndroid(req RequestPushNotification) bool { res, err := gcm.SendHttp(PushConf.Android.ApiKey, notification) - log.Printf("Success count: %d, Failure count: %d", res.Success, res.Failure) - if err != nil { - log.Println("GCM Server Error Message: " + err.Error()) + // GCM server error + LogError.Error("GCM server error: " + err.Error()) return false } - if res.Error != "" { - log.Println("GCM Http Error Message: " + res.Error) + LogAccess.Debug(fmt.Sprintf("Android Success count: %d, Failure count: %d", res.Success, res.Failure)) - return false - } + for k, result := range res.Results { + if result.Error != "" { + LogPush(StatusFailedPush, req.Tokens[k], req, errors.New(result.Error)) + continue + } - if res.Success > 0 { - return true + LogPush(StatusSucceededPush, req.Tokens[k], req, nil) } return true