1
0
Fork 0

Logging and error reporting

This commit is contained in:
Gregory Eremin 2014-07-12 17:41:10 +07:00
parent 31cd3431c3
commit efc2a306ef
1 changed files with 38 additions and 0 deletions

38
logging.go Normal file
View File

@ -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)
}
}