From efc2a306efe02d0b766f8f0f4bd4d616651a7e16 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sat, 12 Jul 2014 17:41:10 +0700 Subject: [PATCH] Logging and error reporting --- logging.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 logging.go diff --git a/logging.go b/logging.go new file mode 100644 index 0000000..14b8174 --- /dev/null +++ b/logging.go @@ -0,0 +1,38 @@ +package main + +import ( + "github.com/stvp/rollbar" + "log" + "os" +) + +var ( + logger *log.Logger +) + +func SetupLogging() { + logger = log.New(os.Stdout, "", log.Ldate|log.Lmicroseconds) + rollbar.Token = cfg.Rollbar + rollbar.Environment = cfg.Env +} + +func Log(format string, args ...interface{}) { + logger.Printf("[INFO] "+format, args...) +} + +func Debug(format string, args ...interface{}) { + if cfg.Env == "development" { + logger.Printf("[DEBUG]"+format, args...) + } +} + +func Error(err error, format string, args ...interface{}) { + logger.Printf("[ERROR]"+format, args...) + + if cfg.Env == "development" { + panic(err) + } + if cfg.Rollbar != "" { + rollbar.Error("error", err) + } +}