2014-07-12 10:41:10 +00:00
|
|
|
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" {
|
2014-07-15 10:50:04 +00:00
|
|
|
logger.Printf("[DEBUG] "+format, args...)
|
2014-07-12 10:41:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Error(err error, format string, args ...interface{}) {
|
2014-07-15 10:50:04 +00:00
|
|
|
logger.Printf("[ERROR] "+format, args...)
|
2014-07-12 10:41:10 +00:00
|
|
|
|
|
|
|
if cfg.Env == "development" {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if cfg.Rollbar != "" {
|
|
|
|
rollbar.Error("error", err)
|
|
|
|
}
|
|
|
|
}
|