Skip to content

Instantly share code, notes, and snippets.

@chatterjeesunit
Last active August 10, 2020 18:40
Show Gist options
  • Save chatterjeesunit/6929fc7ea2fbd2b803ab768071977f22 to your computer and use it in GitHub Desktop.
Save chatterjeesunit/6929fc7ea2fbd2b803ab768071977f22 to your computer and use it in GitHub Desktop.
var sugarLogger *zap.SugaredLogger
func main() {
InitLogger()
defer sugarLogger.Sync()
SimpleHttpGet("www.google.com")
SimpleHttpGet("http://www.google.com")
}
func InitLogger() {
logger, _ := zap.NewProduction()
sugarLogger = logger.Sugar()
}
func SimpleHttpGet(url string) {
sugarLogger.Debugf("Trying to hit GET request for %s", url)
resp, err := http.Get(url)
if err != nil {
sugarLogger.Errorf("Error fetching URL %s : Error = %s", url, err)
} else {
sugarLogger.Infof("Success! statusCode = %s for URL %s", resp.Status, url)
resp.Body.Close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment