Skip to content

Commit 7d33b02

Browse files
willypuzzlelarkoxagnivade
authored
[MM-19315] Replace old Logger with mlog.Logger (mattermost package) (#130)
* Updated logging in Android and Apple notification servers Refactored the logging system in both Android and Apple notification servers. Replaced `logger.Infof` with `logger.Info` for a more structured logging approach, using `mlog.String`, `mlog.Int`, and `mlog.Err` to provide additional context. This change enhances readability and allows for better log analysis. * Refactored logging for better readability The logging statements in the server and notification files have been refactored to improve readability. The changes include replacing `logger.Errorf` with `logger.Error` and using structured logging fields instead of string formatting. This makes it easier to understand the log messages and their associated data. * Updated server error handling Switched from using Panic to Fatal in the server's error handling mechanism. This change ensures that any serious errors will cause the program to exit immediately, rather than just panicking and potentially leaving the server in an unstable state. * Updated logger type in server modules The logger type has been updated from *Logger to *mlog.Logger in the AndroidNotificationServer, AppleNotificationServer, and Server structures. This change also affects the NewAndroidNotificationServer, NewAppleNotificationServer functions where the logger parameter type is updated accordingly. * Updated push proxy configuration Refactored the ConfigPushProxy struct. Deprecated LogFileLocation, EnableConsoleLog, and EnableFileLog for backward compatibility. Introduced LoggingCfgFile and LoggingCfgJSON as replacements. No changes to other existing fields. * Refactor config loading in push proxy Removed the automatic enabling of console log when both console and file logs are disabled. Also, removed the creation and handling of log files within the configuration loading function. This simplifies the function by focusing it solely on loading configurations. * Enhanced logger initialization and configuration The main function has been updated to include a more robust logger initialization process. This includes error handling for the creation of a new logger, as well as its configuration. If no logging is defined, a default config (console output) is used. A separate function has been added to provide this default logging configuration. The server now also ensures that the logger is properly shut down when it's no longer needed. * Updated Go version and dependencies Upgraded the Go version from 1.21 to 1.22 and updated various dependencies to their latest versions. This includes updates to firebase, gorilla handlers, mux, prometheus client_golang, common, golang.org/x/net and oauth2 among others. Also added new dependencies such as github.com/mattermost/mattermost/server/public and github.com/francoispqt/gojay. * Refactored logging configuration setup The default logging configuration has been refactored to support both console and file logging. The logic for generating the default config has been moved from main.go to a new file, server/logging.go. This change allows the application to dynamically choose between console or file logging based on the 'EnableFileLog' flag in the configuration. * Revert "Updated Go version and dependencies" This reverts commit 8e38a57. * Updated Go version and dependencies Upgraded the Go version from 1.21 to 1.22 and updated various dependencies to their latest versions. Also, added new dependencies required for the project's functionality. * Update Docker image versions The Docker images for Go and Golint have been updated to newer versions. The new version of the Go image includes various performance improvements and bug fixes. Similarly, the Golint image has also been updated to include the latest linting rules and enhancements. * Updated logger initialization in tests The logger initialization in various test files has been updated. Instead of using the NewLogger function, we are now using mlog.NewLogger(). This change affects android_notification_test.go, metrics_test.go, and server_test.go. * Improved error handling and logging configuration - Added error checks after initializing new loggers in various test functions to ensure no silent failures. - Simplified the condition check for enabling file logs by directly using the boolean value. * Added logging tests Introduced a new set of unit tests for the server's logging functionality. These tests cover various aspects such as escaping double quotes, default console log configuration, file log configuration and overall logging configuration. Also added a helper function to generate random strings for testing purposes. * Updated logging configuration in JSON The logging settings have been simplified and restructured. The previous console and file log enablement flags have been removed. Instead, a new approach has been introduced where the logging configuration is now handled through a dedicated config file or directly via JSON. * Added new logging configuration file A new JSON configuration file for logging has been added. This includes settings for console type output, plain formatting, and color enabling. It also specifies minimum lengths for level and message, as well as the inclusion of caller information. Different log levels from debug to panic have been defined with corresponding IDs and optional color or stacktrace attributes. * Refactored logger initialization and configuration The logger initialization and configuration process has been refactored for better code organization. The logic previously in the main function is now encapsulated within a new function, NewMlogLogger, in the server package. This change also includes updates to logging tests to accommodate the new structure. * Updated Push Proxy to version 5.9.0 This update includes several significant changes: - The release is compatible with all versions of Mattermost server and mobile. - Notably, Google Cloud Messaging (GCM) service has been deprecated as of April 10, 2018, and will be removed by April 11, 2019. Migration to Firebase Cloud Messaging (FCM) is necessary. - The old Logger system has been replaced with a new one. - Deprecated types EnableConsoleLog, EnableFileLog, and LogFileLocation from the config have been replaced. - Lastly, we've switched from go version 1.21 to go version 1.22 for improved performance and stability. * Updated README with CHANGELOG reference The README file has been updated to include a reference to the CHANGELOG. This will provide users with more detailed information about the changes made in each release. * Update server/logging.go test logic Co-authored-by: Daniel Espino García <[email protected]> * Refactor logging configuration logic The logging configuration logic has been refactored for better readability. The changes mainly involve reformatting the conditionals that determine whether to use console or file log configurations. * Refactored logging tests for better readability The logging tests have been refactored to improve readability and maintainability. The changes include: - Grouping related assertions into subtests using t.Run - Using require instead of assert where appropriate to stop test execution after a failure - Simplifying variable declarations by using the new keyword * Updated dependencies in go.mod and go.sum Several new dependencies have been added to the project's go.mod and go.sum files. This includes libraries for handling semantic versioning, color output, OpenGraph protocol, LDAP support, and more. These additions will provide necessary functionality for upcoming features and improvements. * Refactor logging tests and remove random string generation The logging test functions have been refactored for clarity, removing the 'OK' suffix from their names. The random string generation function has been removed and replaced with model.NewId() for filename creation in file log configuration tests. This change simplifies the codebase and improves readability of the test cases. * Refactor logging configuration The logging configuration has been refactored to simplify the process. Deprecated fields have been removed from the ConfigPushProxy struct and replaced with a single LogFormat field. The NewMlogLogger function now uses this new field to determine the log format, defaulting to "plain" if an invalid value is provided. Additionally, helper functions have been created to build the logger configuration for both console and file outputs based on these changes. Corresponding tests have also been updated accordingly. * Removed logging config file and updated logging settings The logging configuration file has been removed. Logging settings have been directly integrated into the main configuration file. This includes disabling console and file logs by default, specifying log format, and removing specific log level definitions. * Revert "Updated README with CHANGELOG reference" This reverts commit 02a6b10. * Revert "Updated Push Proxy to version 5.9.0" This reverts commit 4af221e. * Enabled console logging The configuration has been updated to enable console logging. This change will allow for better tracking and debugging of the application's activities. * Updated golangci-lint version in Docker image The version of golangci-lint used in the Docker image has been downgraded. This was done to ensure compatibility with other components and improve overall stability. * Removed logging functionality The logging functionality and its associated tests have been removed from the server. This includes the deletion of functions for creating new loggers, building log configurations, and configuring console and file logs. The changes aim to simplify the codebase by eliminating unnecessary components. * Refactored import statements in multiple files The import statements for the 'mlog' package and a few others have been restructured across several server files. This change improves readability and consistency of the codebase. * Refactored logging system The existing logging system has been replaced with a more flexible one. The new logger is based on the mlog library, which allows for different log formats and configurable targets. This change also includes updates to the logger configuration process and removes some helper methods that were previously used in the application. Tests have been updated accordingly to reflect these changes. * Updated logging messages for notifications The logging messages in the Android and Apple notification servers have been updated to improve clarity. The changes include: - Removed specific identifiers from the log messages when sending push notifications. - Standardized the naming convention of 'ack_id' across all logs. - Simplified log message when initializing apple notification server with AuthKey. - Updated acknowledgment delivery receipt log message for better readability. * Enhanced logging and timeout configuration Added logic to ensure at least one type of logging (console or file) is enabled. If both are disabled, console logging will be turned on by default. For file logging, if the log file location is not specified, it will create a new directory for logs and set the log file location there. If the directory creation fails, it logs in the current directory itself. Also ensured that if the log file does not exist, it gets created. Additionally, refined timeout settings by setting defaults if they're not provided in the configuration. * Refactor logger initialization Simplified the logger initialization process by removing unnecessary comments and renaming the function used to create a new logger. This change makes the code cleaner and easier to read. * fix more issues * Empty commit * Revert "Empty commit" This reverts commit e35b0d6. * Trigger CI --------- Co-authored-by: Daniel Espino García <[email protected]> Co-authored-by: Agniva De Sarker <[email protected]>
1 parent 93d8c3b commit 7d33b02

14 files changed

+404
-255
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ifneq ($(shell echo $(APP_VERSION) | egrep '^v([0-9]+\.){0,2}(\*|[0-9]+)'),)
6464
endif
6565

6666
## Docker Images
67-
DOCKER_IMAGE_GO ?= "golang:${GO_VERSION}@sha256:d83472f1ab5712a6b2b816dc811e46155e844ddc02f5f5952e72c6deedafed77"
67+
DOCKER_IMAGE_GO ?= "golang:${GO_VERSION}@sha256:21edeab9ed48e9820f0b447cce6ce1900b3aa90ffce3c8b4de7fae5ac333de0c"
6868
DOCKER_IMAGE_GOLINT ?= "golangci/golangci-lint:v1.57.2@sha256:8f3a60a00a83bb7d599d2e028ac0c3573dc2b9ec0842590f1c2e59781c821da7"
6969
DOCKER_IMAGE_DOCKERLINT ?= "hadolint/hadolint:v2.12.0"
7070
DOCKER_IMAGE_COSIGN ?= "bitnami/cosign:1.8.0@sha256:8c2c61c546258fffff18b47bb82a65af6142007306b737129a7bd5429d53629a"

config/mattermost-push-proxy.sample.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@
4040
],
4141
"EnableConsoleLog": true,
4242
"EnableFileLog": false,
43-
"LogFileLocation": ""
43+
"LogFileLocation": "",
44+
"LogFormat": "plain"
4445
}

go.mod

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
module github.com/mattermost/mattermost-push-proxy
22

3-
go 1.21
3+
go 1.22
44

5-
toolchain go1.21.9
5+
toolchain go1.22.10
66

77
require (
88
firebase.google.com/go/v4 v4.14.0
99
github.com/gorilla/handlers v1.5.2
1010
github.com/gorilla/mux v1.8.1
1111
github.com/kyokomi/emoji v2.2.4+incompatible
12+
github.com/mattermost/mattermost/server/public v0.1.9
1213
github.com/prometheus/client_golang v1.19.0
1314
github.com/prometheus/common v0.53.0
1415
github.com/sideshow/apns2 v0.23.0
1516
github.com/stretchr/testify v1.9.0
16-
golang.org/x/net v0.24.0
17-
golang.org/x/oauth2 v0.19.0
17+
golang.org/x/net v0.27.0
18+
golang.org/x/oauth2 v0.21.0
1819
google.golang.org/api v0.176.1
19-
gopkg.in/natefinch/lumberjack.v2 v2.2.1
2020
gopkg.in/throttled/throttled.v1 v1.0.0
2121
)
2222

@@ -33,8 +33,9 @@ require (
3333
github.com/PuerkitoBio/boom v0.0.0-20140219125548-fecdef1c97ca // indirect
3434
github.com/beorn7/perks v1.0.1 // indirect
3535
github.com/cespare/xxhash/v2 v2.3.0 // indirect
36-
github.com/davecgh/go-spew v1.1.1 // indirect
36+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3737
github.com/felixge/httpsnoop v1.0.4 // indirect
38+
github.com/francoispqt/gojay v1.2.13 // indirect
3839
github.com/garyburd/redigo v1.6.4 // indirect
3940
github.com/go-logr/logr v1.4.1 // indirect
4041
github.com/go-logr/stdr v1.2.2 // indirect
@@ -46,28 +47,33 @@ require (
4647
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
4748
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
4849
github.com/kr/text v0.2.0 // indirect
50+
github.com/mattermost/logr/v2 v2.0.21 // indirect
4951
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 // indirect
50-
github.com/pmezard/go-difflib v1.0.0 // indirect
52+
github.com/pkg/errors v0.9.1 // indirect
53+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
5154
github.com/prometheus/client_model v0.6.1 // indirect
5255
github.com/prometheus/procfs v0.14.0 // indirect
5356
github.com/rakyll/pb v0.0.0-20160123035540-8d46b8b097ef // indirect
5457
github.com/rogpeppe/go-internal v1.11.0 // indirect
58+
github.com/wiggin77/merror v1.0.5 // indirect
59+
github.com/wiggin77/srslog v1.0.1 // indirect
5560
go.opencensus.io v0.24.0 // indirect
5661
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect
5762
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
5863
go.opentelemetry.io/otel v1.26.0 // indirect
5964
go.opentelemetry.io/otel/metric v1.26.0 // indirect
6065
go.opentelemetry.io/otel/trace v1.26.0 // indirect
61-
golang.org/x/crypto v0.22.0 // indirect
66+
golang.org/x/crypto v0.25.0 // indirect
6267
golang.org/x/sync v0.7.0 // indirect
63-
golang.org/x/sys v0.19.0 // indirect
64-
golang.org/x/text v0.14.0 // indirect
68+
golang.org/x/sys v0.22.0 // indirect
69+
golang.org/x/text v0.16.0 // indirect
6570
golang.org/x/time v0.5.0 // indirect
6671
google.golang.org/appengine/v2 v2.0.6 // indirect
6772
google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be // indirect
68-
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
69-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
70-
google.golang.org/grpc v1.63.2 // indirect
71-
google.golang.org/protobuf v1.33.0 // indirect
73+
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
74+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade // indirect
75+
google.golang.org/grpc v1.65.0 // indirect
76+
google.golang.org/protobuf v1.34.2 // indirect
77+
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
7278
gopkg.in/yaml.v3 v3.0.1 // indirect
7379
)

go.sum

Lines changed: 165 additions & 20 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ func main() {
3939
log.Fatal(err)
4040
}
4141

42-
logger := server.NewLogger(cfg)
42+
logger, err := server.NewLogger(cfg)
43+
defer func() {
44+
if logger != nil {
45+
_ = logger.Shutdown()
46+
}
47+
}()
48+
if err != nil {
49+
log.Fatal(err)
50+
}
51+
4352
logger.Info("Loading " + fileName)
4453

4554
srv := server.New(cfg, logger)

server/android_notification_server.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/kyokomi/emoji"
1919
"golang.org/x/oauth2/google"
2020
"google.golang.org/api/option"
21+
22+
"github.com/mattermost/mattermost/server/public/shared/mlog"
2123
)
2224

2325
const (
@@ -37,7 +39,7 @@ const (
3739

3840
type AndroidNotificationServer struct {
3941
metrics *metrics
40-
logger *Logger
42+
logger *mlog.Logger
4143
AndroidPushSettings AndroidPushSettings
4244
client *messaging.Client
4345
sendTimeout time.Duration
@@ -54,7 +56,7 @@ type serviceAccount struct {
5456
TokenURI string `json:"token_uri"`
5557
}
5658

57-
func NewAndroidNotificationServer(settings AndroidPushSettings, logger *Logger, metrics *metrics, sendTimeoutSecs int) *AndroidNotificationServer {
59+
func NewAndroidNotificationServer(settings AndroidPushSettings, logger *mlog.Logger, metrics *metrics, sendTimeoutSecs int) *AndroidNotificationServer {
5860
return &AndroidNotificationServer{
5961
AndroidPushSettings: settings,
6062
metrics: metrics,
@@ -64,10 +66,10 @@ func NewAndroidNotificationServer(settings AndroidPushSettings, logger *Logger,
6466
}
6567

6668
func (me *AndroidNotificationServer) Initialize() error {
67-
me.logger.Infof("Initializing Android notification server for type=%v", me.AndroidPushSettings.Type)
69+
me.logger.Info("Initializing Android notification server", mlog.String("type", me.AndroidPushSettings.Type))
6870

6971
if me.AndroidPushSettings.AndroidAPIKey != "" {
70-
me.logger.Infof("AndroidPushSettings.AndroidAPIKey is no longer used. Please remove this config value.")
72+
me.logger.Info("AndroidPushSettings.AndroidAPIKey is no longer used. Please remove this config value.")
7173
}
7274

7375
if me.AndroidPushSettings.ServiceFileLocation == "" {
@@ -169,7 +171,12 @@ func (me *AndroidNotificationServer) SendNotification(msg *PushNotification) Pus
169171
ctx, cancel := context.WithTimeout(context.Background(), me.sendTimeout)
170172
defer cancel()
171173

172-
me.logger.Infof("Sending android push notification for device=%v type=%v ackId=%v", me.AndroidPushSettings.Type, msg.Type, msg.AckID)
174+
me.logger.Info(
175+
"Sending android push notification",
176+
mlog.String("device", me.AndroidPushSettings.Type),
177+
mlog.String("type", msg.Type),
178+
mlog.String("ack_id", msg.AckID),
179+
)
173180

174181
start := time.Now()
175182
_, err := me.client.Send(ctx, fcmMsg)
@@ -183,17 +190,17 @@ func (me *AndroidNotificationServer) SendNotification(msg *PushNotification) Pus
183190
errorCode = "NONE"
184191
}
185192

186-
me.logger.Errorf(
187-
"Failed to send FCM push sid=%v did=%v err=%v type=%v errorCode=%v",
188-
msg.ServerID,
189-
msg.DeviceID,
190-
err,
191-
me.AndroidPushSettings.Type,
192-
errorCode,
193+
me.logger.Error(
194+
"Failed to send FCM push",
195+
mlog.String("sid", msg.ServerID),
196+
mlog.String("did", msg.DeviceID),
197+
mlog.Err(err),
198+
mlog.String("type", me.AndroidPushSettings.Type),
199+
mlog.String("errorCode", errorCode),
193200
)
194201

195202
if messaging.IsUnregistered(err) || messaging.IsSenderIDMismatch(err) {
196-
me.logger.Infof("Android response failure sending remove code: type=%v", me.AndroidPushSettings.Type)
203+
me.logger.Info("Android response failure sending remove code", mlog.String("type", me.AndroidPushSettings.Type))
197204
if me.metrics != nil {
198205
me.metrics.incrementRemoval(PushNotifyAndroid, pushType, unregistered)
199206
}

server/android_notification_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import (
1111
"testing"
1212

1313
"github.com/stretchr/testify/require"
14+
15+
"github.com/mattermost/mattermost/server/public/shared/mlog"
1416
)
1517

1618
func TestAndroidInitialize(t *testing.T) {
1719
fileName := FindConfigFile("mattermost-push-proxy.sample.json")
1820
cfg, err := LoadConfig(fileName)
1921
require.NoError(t, err)
2022

21-
logger := NewLogger(cfg)
23+
logger, err := mlog.NewLogger()
24+
require.NoError(t, err)
2225

2326
// Verify error for no service file
2427
pushSettings := AndroidPushSettings{}

server/apple_notification_server.go

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ import (
1717
"github.com/sideshow/apns2/payload"
1818
"github.com/sideshow/apns2/token"
1919
"golang.org/x/net/http2"
20+
21+
"github.com/mattermost/mattermost/server/public/shared/mlog"
2022
)
2123

2224
type AppleNotificationServer struct {
2325
AppleClient *apns.Client
2426
metrics *metrics
25-
logger *Logger
27+
logger *mlog.Logger
2628
ApplePushSettings ApplePushSettings
2729
sendTimeout time.Duration
2830
retryTimeout time.Duration
2931
}
3032

31-
func NewAppleNotificationServer(settings ApplePushSettings, logger *Logger, metrics *metrics, sendTimeoutSecs int, retryTimeoutSecs int) *AppleNotificationServer {
33+
func NewAppleNotificationServer(settings ApplePushSettings, logger *mlog.Logger, metrics *metrics, sendTimeoutSecs int, retryTimeoutSecs int) *AppleNotificationServer {
3234
return &AppleNotificationServer{
3335
ApplePushSettings: settings,
3436
metrics: metrics,
@@ -64,9 +66,9 @@ func (me *AppleNotificationServer) setupProxySettings(appleCert *tls.Certificate
6466
}
6567

6668
if appleCert != nil {
67-
me.logger.Infof("Initializing apple notification server for type=%v with PEM certificate", me.ApplePushSettings.Type)
69+
me.logger.Info("Initializing apple notification server with PEM certificate", mlog.String("type", me.ApplePushSettings.Type))
6870
} else {
69-
me.logger.Infof("Initializing apple notification server for type=%v with AuthKey", me.ApplePushSettings.Type)
71+
me.logger.Info("Initializing apple notification server with AuthKey", mlog.String("type", me.ApplePushSettings.Type))
7072
}
7173

7274
return nil
@@ -228,11 +230,22 @@ func (me *AppleNotificationServer) SendNotification(msg *PushNotification) PushR
228230
}
229231

230232
if me.AppleClient != nil {
231-
me.logger.Infof("Sending apple push notification for device=%v type=%v ackId=%v", me.ApplePushSettings.Type, msg.Type, msg.AckID)
233+
me.logger.Info(
234+
"Sending apple push notification",
235+
mlog.String("device", me.ApplePushSettings.Type),
236+
mlog.String("type", msg.Type),
237+
mlog.String("ack_id", msg.AckID),
238+
)
232239

233240
res, err := me.SendNotificationWithRetry(notification)
234241
if err != nil {
235-
me.logger.Errorf("Failed to send apple push sid=%v did=%v err=%v type=%v", msg.ServerID, msg.DeviceID, err, me.ApplePushSettings.Type)
242+
me.logger.Error(
243+
"Failed to send apple push",
244+
mlog.String("sid", msg.ServerID),
245+
mlog.String("did", msg.DeviceID),
246+
mlog.Err(err),
247+
mlog.String("type", me.ApplePushSettings.Type),
248+
)
236249
if me.metrics != nil {
237250
me.metrics.incrementFailure(PushNotifyApple, pushType, "RequestError")
238251
}
@@ -241,14 +254,26 @@ func (me *AppleNotificationServer) SendNotification(msg *PushNotification) PushR
241254

242255
if !res.Sent() {
243256
if res.Reason == apns.ReasonBadDeviceToken || res.Reason == apns.ReasonUnregistered || res.Reason == apns.ReasonMissingDeviceToken || res.Reason == apns.ReasonDeviceTokenNotForTopic {
244-
me.logger.Infof("Failed to send apple push sending remove code res ApnsID=%v reason=%v code=%v type=%v", res.ApnsID, res.Reason, res.StatusCode, me.ApplePushSettings.Type)
257+
me.logger.Info(
258+
"Failed to send apple push sending remove code res",
259+
mlog.String("ApnsID", res.ApnsID),
260+
mlog.String("reason", res.Reason),
261+
mlog.Int("code", res.StatusCode),
262+
mlog.String("type", me.ApplePushSettings.Type),
263+
)
245264
if me.metrics != nil {
246265
me.metrics.incrementRemoval(PushNotifyApple, pushType, res.Reason)
247266
}
248267
return NewRemovePushResponse()
249268
}
250269

251-
me.logger.Errorf("Failed to send apple push with res ApnsID=%v reason=%v code=%v type=%v", res.ApnsID, res.Reason, res.StatusCode, me.ApplePushSettings.Type)
270+
me.logger.Error(
271+
"Failed to send apple push with res",
272+
mlog.String("ApnsID", res.ApnsID),
273+
mlog.String("reason", res.Reason),
274+
mlog.Int("code", res.StatusCode),
275+
mlog.String("type", me.ApplePushSettings.Type),
276+
)
252277
if me.metrics != nil {
253278
me.metrics.incrementFailure(PushNotifyApple, pushType, res.Reason)
254279
}
@@ -289,10 +314,15 @@ func (me *AppleNotificationServer) SendNotificationWithRetry(notification *apns.
289314
break
290315
}
291316

292-
me.logger.Errorf("Failed to send apple push did=%v retry=%v error=%v", notification.DeviceToken, retries, err)
317+
me.logger.Error(
318+
"Failed to send apple push",
319+
mlog.String("did", notification.DeviceToken),
320+
mlog.Int("retry", retries),
321+
mlog.Err(err),
322+
)
293323

294324
if retries == MAX_RETRIES-1 {
295-
me.logger.Errorf("Max retries reached did=%v", notification.DeviceToken)
325+
me.logger.Error("Max retries reached", mlog.String("did", notification.DeviceToken))
296326
break
297327
}
298328

@@ -302,7 +332,12 @@ func (me *AppleNotificationServer) SendNotificationWithRetry(notification *apns.
302332
}
303333

304334
if generalContext.Err() != nil {
305-
me.logger.Infof("Not retrying because context error did=%v retry=%v error=%v", notification.DeviceToken, retries, generalContext.Err())
335+
me.logger.Info(
336+
"Not retrying because context error",
337+
mlog.String("did", notification.DeviceToken),
338+
mlog.Int("retry", retries),
339+
mlog.Err(generalContext.Err()),
340+
)
306341
err = generalContext.Err()
307342
break
308343
}

server/config_push_proxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type ConfigPushProxy struct {
2222
EnableMetrics bool
2323
EnableConsoleLog bool
2424
EnableFileLog bool
25+
LogFormat string // json or plain
2526
ThrottlePerSec int
2627
ThrottleMemoryStoreSize int
2728
}
@@ -78,7 +79,7 @@ func LoadConfig(fileName string) (*ConfigPushProxy, error) {
7879
fmt.Println(buf, err)
7980
return nil, err
8081
}
81-
// If both are disabled, that means an old config file is being used. Atleast enable console log.
82+
8283
if !cfg.EnableConsoleLog && !cfg.EnableFileLog {
8384
cfg.EnableConsoleLog = true
8485
}

0 commit comments

Comments
 (0)