2014-07-12 10:41:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stvp/rollbar"
|
|
|
|
"log"
|
|
|
|
"os"
|
2014-07-15 20:11:10 +00:00
|
|
|
"runtime"
|
2014-07-12 10:41:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
logger *log.Logger
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetupLogging() {
|
|
|
|
logger = log.New(os.Stdout, "", log.Ldate|log.Lmicroseconds)
|
2014-07-15 19:46:22 +00:00
|
|
|
rollbar.Token = Config.Rollbar
|
|
|
|
rollbar.Environment = Config.Env
|
2014-07-15 20:11:10 +00:00
|
|
|
|
|
|
|
Log("Burlesque started in %s environment", Config.Env)
|
|
|
|
Log("GOMAXPROCS is set to %d", runtime.GOMAXPROCS(-1))
|
|
|
|
Log("Storage path: %s", Config.Storage)
|
|
|
|
Log("Server is running at http://127.0.0.1:%d", Config.Port)
|
|
|
|
if Config.Rollbar == "" {
|
|
|
|
Log("Rollbar is not configured and disabled")
|
|
|
|
} else {
|
|
|
|
Log("Rollbar token: %s", Config.Rollbar)
|
|
|
|
}
|
2014-07-12 10:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Log(format string, args ...interface{}) {
|
|
|
|
logger.Printf("[INFO] "+format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Debug(format string, args ...interface{}) {
|
2014-07-15 19:46:22 +00:00
|
|
|
if Config.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
|
|
|
|
2014-07-15 19:46:22 +00:00
|
|
|
if Config.Env == "development" {
|
2014-07-12 10:41:10 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
2014-07-15 19:46:22 +00:00
|
|
|
if Config.Rollbar != "" {
|
2014-07-12 10:41:10 +00:00
|
|
|
rollbar.Error("error", err)
|
|
|
|
}
|
|
|
|
}
|