View Uber-GoZap - SugarLogger - Custom02.go
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
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
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
func InitLogger() { | |
writerSyncer := getLogWriter() | |
encoder := getEncoder() | |
core := zapcore.NewCore(encoder, writerSyncer, zapcore.DebugLevel) | |
logger := zap.New(core) | |
sugarLogger = logger.Sugar() | |
} |
View Uber-GoZap - SugarLogger 01.go
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
var sugarLogger *zap.SugaredLogger | |
func main() { | |
InitLogger() | |
defer sugarLogger.Sync() | |
SimpleHttpGet("www.google.com") | |
SimpleHttpGet("http://www.google.com") | |
} |
View Uber-GoZap - BasicLogger.go
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
var logger *zap.Logger | |
func main() { | |
InitLogger() | |
defer logger.Sync() | |
SimpleHttpGet("www.google.com") | |
SimpleHttpGet("http://www.google.com") | |
} | |
View SimpleHttpGet.go
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
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 SetupLogger.go
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
func SetupLogger() { | |
logFileLocation, _ := os.OpenFile("/Users/in-sunit.chatterjee/test.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0744) | |
log.SetOutput(logFileLocation) | |
} |