Commit 756a4e09 authored by Mo Firouz's avatar Mo Firouz
Browse files

Update stackdriver logging format.

parent 3e77583c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
## limitations under the License.

# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v2.1.1 -t heroiclabs/nakama:2.1.1
# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="v2.1.1-$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"2.1.1-$(git rev-parse --short HEAD)"
# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"$(git rev-parse --short HEAD)"

FROM golang:1.15.3-buster as builder

+10 −17
Original line number Diff line number Diff line
@@ -15,16 +15,13 @@
package server

import (
	"fmt"
	"os"
	"path/filepath"
	"time"

	"strings"

	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
	"gopkg.in/natefinch/lumberjack.v2"
	lumberjack "gopkg.in/natefinch/lumberjack.v2"
)

type LoggingFormat int8
@@ -159,7 +156,7 @@ func newJSONEncoder(format LoggingFormat) zapcore.Encoder {
			MessageKey:     "msg",
			StacktraceKey:  "stacktrace",
			EncodeLevel:    StackdriverLevelEncoder,
			EncodeTime:     StackdriverTimeEncoder,
			EncodeTime:     zapcore.RFC3339TimeEncoder,
			EncodeDuration: zapcore.StringDurationEncoder,
			EncodeCaller:   zapcore.ShortCallerEncoder,
		})
@@ -179,27 +176,23 @@ func newJSONEncoder(format LoggingFormat) zapcore.Encoder {
	})
}

func StackdriverTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
	enc.AppendString(fmt.Sprintf("%d%s", t.Unix(), t.Format(".000000000")))
}

func StackdriverLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
	switch l {
	case zapcore.DebugLevel:
		enc.AppendString("debug")
		enc.AppendString("DEBUG")
	case zapcore.InfoLevel:
		enc.AppendString("info")
		enc.AppendString("INFO")
	case zapcore.WarnLevel:
		enc.AppendString("warning")
		enc.AppendString("WARNING")
	case zapcore.ErrorLevel:
		enc.AppendString("error")
		enc.AppendString("ERROR")
	case zapcore.DPanicLevel:
		enc.AppendString("critical")
		enc.AppendString("CRITICAL")
	case zapcore.PanicLevel:
		enc.AppendString("critical")
		enc.AppendString("CRITICAL")
	case zapcore.FatalLevel:
		enc.AppendString("critical")
		enc.AppendString("CRITICAL")
	default:
		enc.AppendString(fmt.Sprintf("Level(%d)", l))
		enc.AppendString("DEFAULT")
	}
}