Skip to content

Instantly share code, notes, and snippets.

View SetupLogger.go
func SetupLogger() {
logFileLocation, _ := os.OpenFile("/Users/in-sunit.chatterjee/test.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0744)
log.SetOutput(logFileLocation)
}
View SimpleHttpGet.go
func simpleHttpGet(url string) {
resp, err := http.Get(url)
if err != nil {
log.Printf("Error fetching url %s : %s", url, err.Error())
} else {
log.Printf("Status Code for %s : %s", url, resp.Status)
resp.Body.Close()
}
}
View Uber-GoZap - BasicLogger.go
var logger *zap.Logger
func main() {
InitLogger()
defer logger.Sync()
SimpleHttpGet("www.google.com")
SimpleHttpGet("http://www.google.com")
}
View Uber-GoZap - SugarLogger 01.go
var sugarLogger *zap.SugaredLogger
func main() {
InitLogger()
defer sugarLogger.Sync()
SimpleHttpGet("www.google.com")
SimpleHttpGet("http://www.google.com")
}
View Uber-GoZap - SugarLogger - Custom01.go
func InitLogger() {
writerSyncer := getLogWriter()
encoder := getEncoder()
core := zapcore.NewCore(encoder, writerSyncer, zapcore.DebugLevel)
logger := zap.New(core)
sugarLogger = logger.Sugar()
}
View Uber-GoZap - SugarLogger - Custom02.go
var sugarLogger *zap.SugaredLogger
func main() {
InitLogger()
defer sugarLogger.Sync()
SimpleHttpGet("www.google.com")
SimpleHttpGet("http://www.google.com")
}