Created
September 9, 2019 10:03
-
-
Save BNPrashanth/99ba236ae0b750ef17f881e15be7ee34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package logger | |
import ( | |
"github.com/spf13/viper" | |
"go.uber.org/zap" | |
"go.uber.org/zap/zapcore" | |
) | |
var ( | |
// Log variable is a globally accessible variable which will be initialized when the InitializeZapCustomLogger function is executed successfully. | |
Log *zap.Logger | |
) | |
/* | |
InitializeZapCustomLogger Funtion initializes a logger using uber-go/zap package in the application. | |
*/ | |
func InitializeZapCustomLogger() { | |
conf := zap.Config{ | |
Encoding: "json", | |
Level: zap.NewAtomicLevelAt(zapcore.InfoLevel), | |
OutputPaths: []string{viper.GetString("logger-output-path"), "stdout"}, | |
EncoderConfig: zapcore.EncoderConfig{ | |
LevelKey: "level", | |
TimeKey: "time", | |
CallerKey: "file", | |
MessageKey: "msg", | |
EncodeLevel: zapcore.LowercaseLevelEncoder, | |
EncodeTime: zapcore.ISO8601TimeEncoder, | |
EncodeCaller: zapcore.ShortCallerEncoder, | |
}, | |
} | |
Log, _ = conf.Build() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment