burlesque/logging.go

41 lines
813 B
Go
Raw Normal View History

2014-07-12 17:41:10 +07:00
package main
import (
"log"
"os"
"runtime"
2014-07-12 17:41:10 +07:00
)
var (
logger *log.Logger
)
func SetupLogging() {
logger = log.New(os.Stdout, "", log.Ldate|log.Lmicroseconds)
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)
2014-07-12 17:41:10 +07:00
}
func Log(format string, args ...interface{}) {
logger.Printf("[INFO] "+format, args...)
}
func Debug(format string, args ...interface{}) {
2014-07-16 02:46:22 +07:00
if Config.Env == "development" {
2014-07-15 17:50:04 +07:00
logger.Printf("[DEBUG] "+format, args...)
2014-07-12 17:41:10 +07:00
}
}
func Error(err error, format string, args ...interface{}) {
2014-07-15 17:50:04 +07:00
logger.Printf("[ERROR] "+format, args...)
2014-07-12 17:41:10 +07:00
2014-07-16 02:46:22 +07:00
if Config.Env == "development" {
2014-07-12 17:41:10 +07:00
panic(err)
2014-07-29 13:25:46 +07:00
} else {
logger.Printf(" ", err.Error())
2014-07-12 17:41:10 +07:00
}
}