1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 07:01:28 +00:00

Merge pull request #2 from astaxie/develop

pull from stable
This commit is contained in:
MrLee.Kun 2015-06-19 11:09:11 +08:00
commit 31e5edbdcf
6 changed files with 35 additions and 26 deletions

View File

@ -37,7 +37,7 @@ import (
) )
// beego web framework version. // beego web framework version.
const VERSION = "1.4.3" const VERSION = "1.5.0"
type hookfunc func() error //hook function to run type hookfunc func() error //hook function to run
var hooks []hookfunc //hook function slice to store the hookfunc var hooks []hookfunc //hook function slice to store the hookfunc
@ -336,7 +336,7 @@ func initBeforeHttpRun() {
// this function is for test package init // this function is for test package init
func TestBeegoInit(apppath string) { func TestBeegoInit(apppath string) {
AppPath = apppath AppPath = apppath
RunMode = "test" os.Setenv("BEEGO_RUNMODE", "test")
AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") AppConfigPath = filepath.Join(AppPath, "conf", "app.conf")
err := ParseConfig() err := ParseConfig()
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {

View File

@ -527,7 +527,7 @@ func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader,
// } // }
// } // }
func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) { func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) {
files, ok := c.Ctx.Request.MultipartForm.File["key"] files, ok := c.Ctx.Request.MultipartForm.File[key]
if ok { if ok {
return files, nil return files, nil
} }

10
log.go
View File

@ -78,9 +78,9 @@ func Warning(v ...interface{}) {
BeeLogger.Warning(generateFmtStr(len(v)), v...) BeeLogger.Warning(generateFmtStr(len(v)), v...)
} }
// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. // compatibility alias for Warning()
func Warn(v ...interface{}) { func Warn(v ...interface{}) {
Warning(v...) BeeLogger.Warn(generateFmtStr(len(v)), v...)
} }
func Notice(v ...interface{}) { func Notice(v ...interface{}) {
@ -92,9 +92,9 @@ func Informational(v ...interface{}) {
BeeLogger.Informational(generateFmtStr(len(v)), v...) BeeLogger.Informational(generateFmtStr(len(v)), v...)
} }
// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. // compatibility alias for Warning()
func Info(v ...interface{}) { func Info(v ...interface{}) {
Informational(v...) BeeLogger.Info(generateFmtStr(len(v)), v...)
} }
// Debug logs a message at debug level. // Debug logs a message at debug level.
@ -103,7 +103,7 @@ func Debug(v ...interface{}) {
} }
// Trace logs a message at trace level. // Trace logs a message at trace level.
// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. // compatibility alias for Warning()
func Trace(v ...interface{}) { func Trace(v ...interface{}) {
BeeLogger.Trace(generateFmtStr(len(v)), v...) BeeLogger.Trace(generateFmtStr(len(v)), v...)
} }

View File

@ -157,18 +157,15 @@ func (bl *BeeLogger) writerMsg(loglevel int, msg string) error {
lm.level = loglevel lm.level = loglevel
if bl.enableFuncCallDepth { if bl.enableFuncCallDepth {
_, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth) _, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth)
if _, filename := path.Split(file); filename == "log.go" && (line == 97 || line == 83) { if !ok {
_, file, line, ok = runtime.Caller(bl.loggerFuncCallDepth + 1) file = "???"
line = 0
} }
if ok {
_, filename := path.Split(file) _, filename := path.Split(file)
lm.msg = fmt.Sprintf("[%s:%d] %s", filename, line, msg) lm.msg = fmt.Sprintf("[%s:%d] %s", filename, line, msg)
} else { } else {
lm.msg = msg lm.msg = msg
} }
} else {
lm.msg = msg
}
if bl.asynchronous { if bl.asynchronous {
bl.msg <- lm bl.msg <- lm
} else { } else {
@ -295,24 +292,33 @@ func (bl *BeeLogger) Debug(format string, v ...interface{}) {
} }
// Log WARN level message. // Log WARN level message.
// // compatibility alias for Warning()
// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0.
func (bl *BeeLogger) Warn(format string, v ...interface{}) { func (bl *BeeLogger) Warn(format string, v ...interface{}) {
bl.Warning(format, v...) if LevelWarning > bl.level {
return
}
msg := fmt.Sprintf("[W] "+format, v...)
bl.writerMsg(LevelWarning, msg)
} }
// Log INFO level message. // Log INFO level message.
// // compatibility alias for Informational()
// Deprecated: compatibility alias for Informational(), Will be removed in 1.5.0.
func (bl *BeeLogger) Info(format string, v ...interface{}) { func (bl *BeeLogger) Info(format string, v ...interface{}) {
bl.Informational(format, v...) if LevelInformational > bl.level {
return
}
msg := fmt.Sprintf("[I] "+format, v...)
bl.writerMsg(LevelInformational, msg)
} }
// Log TRACE level message. // Log TRACE level message.
// // compatibility alias for Debug()
// Deprecated: compatibility alias for Debug(), Will be removed in 1.5.0.
func (bl *BeeLogger) Trace(format string, v ...interface{}) { func (bl *BeeLogger) Trace(format string, v ...interface{}) {
bl.Debug(format, v...) if LevelDebug > bl.level {
return
}
msg := fmt.Sprintf("[D] "+format, v...)
bl.writerMsg(LevelDebug, msg)
} }
// flush all chan data. // flush all chan data.

View File

@ -611,6 +611,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if p.enableFilter { if p.enableFilter {
if l, ok := p.filters[pos]; ok { if l, ok := p.filters[pos]; ok {
for _, filterR := range l { for _, filterR := range l {
if filterR.returnOnOutput && w.started {
return true
}
if ok, params := filterR.ValidRouter(urlPath); ok { if ok, params := filterR.ValidRouter(urlPath); ok {
for k, v := range params { for k, v := range params {
context.Input.Params[k] = v context.Input.Params[k] = v

View File

@ -58,7 +58,7 @@ func serverStaticRouter(ctx *context.Context) {
finfo, err := os.Stat(file) finfo, err := os.Stat(file)
if err != nil { if err != nil {
if RunMode == "dev" { if RunMode == "dev" {
Warn(err) Warn("Can't find the file:", file, err)
} }
http.NotFound(ctx.ResponseWriter, ctx.Request) http.NotFound(ctx.ResponseWriter, ctx.Request)
return return