From 3f1de576e425fc914a5cd1a1a828f298f2694934 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 4 Apr 2014 09:49:55 +0800 Subject: [PATCH] fix go run hello.go & console log --- beego.go | 2 +- config.go | 8 ++++++-- logs/conn.go | 3 --- logs/file.go | 3 --- logs/smtp.go | 3 --- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/beego.go b/beego.go index 52b2ef92..112ecd4b 100644 --- a/beego.go +++ b/beego.go @@ -188,7 +188,7 @@ func initBeforeHttpRun() { // if AppConfigPath not In the conf/app.conf reParse config if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") { err := ParseConfig() - if err != nil { + if err != nil && AppConfigPath != filepath.Join(workPath, "conf", "app.conf") { // configuration is critical to app, panic here if parse failed panic(err) } diff --git a/config.go b/config.go index a963ac02..6abc1b68 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,7 @@ package beego import ( + "fmt" "html/template" "os" "path/filepath" @@ -143,9 +144,12 @@ func init() { // init BeeLogger BeeLogger = logs.NewLogger(10000) - BeeLogger.SetLogger("console", "") + err := BeeLogger.SetLogger("console", "") + if err != nil { + fmt.Println("init console log error:", err) + } - err := ParseConfig() + err = ParseConfig() if err != nil && !os.IsNotExist(err) { // for init if doesn't have app.conf will not panic Info(err) diff --git a/logs/conn.go b/logs/conn.go index 77bf4de8..eed9ae2f 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -29,9 +29,6 @@ func NewConn() LoggerInterface { // init connection writer with json config. // json config only need key "level". func (c *ConnWriter) Init(jsonconfig string) error { - if len(jsonconfig) == 0 { - return nil - } err := json.Unmarshal([]byte(jsonconfig), c) if err != nil { return err diff --git a/logs/file.go b/logs/file.go index c9f81df5..9400e04d 100644 --- a/logs/file.go +++ b/logs/file.go @@ -90,9 +90,6 @@ func NewFileWriter() LoggerInterface { // "rotate":true // } func (w *FileLogWriter) Init(jsonconfig string) error { - if len(jsonconfig) == 0 { - return nil - } err := json.Unmarshal([]byte(jsonconfig), w) if err != nil { return err diff --git a/logs/smtp.go b/logs/smtp.go index ec1c61ca..19296887 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -38,9 +38,6 @@ func NewSmtpWriter() LoggerInterface { // "level":LevelError // } func (s *SmtpWriter) Init(jsonconfig string) error { - if len(jsonconfig) == 0 { - return nil - } err := json.Unmarshal([]byte(jsonconfig), s) if err != nil { return err