mirror of
https://github.com/beego/bee.git
synced 2024-11-26 01:11:30 +00:00
Fixes the filename and lineNo in debug log message
This commit is contained in:
parent
c3c264ddb5
commit
deacdaa667
@ -658,7 +658,7 @@ func checkEnv(appname string) (apppath, packpath string, err error) {
|
|||||||
gopath := gps[0]
|
gopath := gps[0]
|
||||||
|
|
||||||
logger.Warn("You current workdir is not inside $GOPATH/src")
|
logger.Warn("You current workdir is not inside $GOPATH/src")
|
||||||
logger.Debugf("GOPATH: %s", gopath)
|
logger.Debugf("GOPATH: %s", __FILE__(), __LINE__(), gopath)
|
||||||
|
|
||||||
gosrcpath := path.Join(gopath, "src")
|
gosrcpath := path.Join(gopath, "src")
|
||||||
apppath = path.Join(gosrcpath, appname)
|
apppath = path.Join(gosrcpath, appname)
|
||||||
|
2
g.go
2
g.go
@ -91,7 +91,7 @@ func generateCode(cmd *Command, args []string) int {
|
|||||||
|
|
||||||
gopath := gps[0]
|
gopath := gps[0]
|
||||||
|
|
||||||
logger.Debugf("GOPATH: %s", gopath)
|
logger.Debugf("GOPATH: %s", __FILE__(), __LINE__(), gopath)
|
||||||
|
|
||||||
gcmd := args[0]
|
gcmd := args[0]
|
||||||
switch gcmd {
|
switch gcmd {
|
||||||
|
@ -954,7 +954,7 @@ func getPackagePath(curpath string) (packpath string) {
|
|||||||
logger.Fatal("GOPATH environment variable is not set or empty")
|
logger.Fatal("GOPATH environment variable is not set or empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Debugf("GOPATH: %s", gopath)
|
logger.Debugf("GOPATH: %s", __FILE__(), __LINE__(), gopath)
|
||||||
|
|
||||||
appsrcpath := ""
|
appsrcpath := ""
|
||||||
haspath := false
|
haspath := false
|
||||||
|
15
logger.go
15
logger.go
@ -19,7 +19,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -155,7 +154,7 @@ func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) {
|
|||||||
|
|
||||||
// mustLogDebug logs a debug message only if debug mode
|
// mustLogDebug logs a debug message only if debug mode
|
||||||
// is enabled. i.e. DEBUG_ENABLED="1"
|
// is enabled. i.e. DEBUG_ENABLED="1"
|
||||||
func (l *BeeLogger) mustLogDebug(message string, args ...interface{}) {
|
func (l *BeeLogger) mustLogDebug(message string, file string, line int, args ...interface{}) {
|
||||||
if !IsDebugEnabled() {
|
if !IsDebugEnabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -163,9 +162,7 @@ func (l *BeeLogger) mustLogDebug(message string, args ...interface{}) {
|
|||||||
// Change the output to Stderr
|
// Change the output to Stderr
|
||||||
l.SetOutput(os.Stderr)
|
l.SetOutput(os.Stderr)
|
||||||
|
|
||||||
// Create the log record and Get the filename
|
// Create the log record
|
||||||
// and the line number of the caller
|
|
||||||
_, file, line, _ := runtime.Caller(1)
|
|
||||||
record := LogRecord{
|
record := LogRecord{
|
||||||
ID: fmt.Sprintf("%04d", atomic.AddUint64(&sequenceNo, 1)),
|
ID: fmt.Sprintf("%04d", atomic.AddUint64(&sequenceNo, 1)),
|
||||||
Level: l.getColorLevel(levelDebug),
|
Level: l.getColorLevel(levelDebug),
|
||||||
@ -178,13 +175,13 @@ func (l *BeeLogger) mustLogDebug(message string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Debug outputs a debug log message
|
// Debug outputs a debug log message
|
||||||
func (l *BeeLogger) Debug(message string) {
|
func (l *BeeLogger) Debug(message string, file string, line int) {
|
||||||
l.mustLogDebug(message)
|
l.mustLogDebug(message, file, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf outputs a formatted debug log message
|
// Debugf outputs a formatted debug log message
|
||||||
func (l *BeeLogger) Debugf(message string, vars ...interface{}) {
|
func (l *BeeLogger) Debugf(message string, file string, line int, vars ...interface{}) {
|
||||||
l.mustLogDebug(message, vars...)
|
l.mustLogDebug(message, file, line, vars...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info outputs an information log message
|
// Info outputs an information log message
|
||||||
|
@ -73,7 +73,7 @@ func runMigration(cmd *Command, args []string) int {
|
|||||||
|
|
||||||
gopath := gps[0]
|
gopath := gps[0]
|
||||||
|
|
||||||
logger.Debugf("GOPATH: %s", gopath)
|
logger.Debugf("GOPATH: %s", __FILE__(), __LINE__(), gopath)
|
||||||
|
|
||||||
// Load the configuration
|
// Load the configuration
|
||||||
err := loadConfig()
|
err := loadConfig()
|
||||||
|
2
run.go
2
run.go
@ -99,7 +99,7 @@ func runApp(cmd *Command, args []string) int {
|
|||||||
|
|
||||||
logger.Infof("Using '%s' as 'appname'", appname)
|
logger.Infof("Using '%s' as 'appname'", appname)
|
||||||
|
|
||||||
logger.Debugf("Current path: %s", currpath)
|
logger.Debugf("Current path: %s", __FILE__(), __LINE__(), currpath)
|
||||||
|
|
||||||
if runmode == "prod" || runmode == "dev" {
|
if runmode == "prod" || runmode == "dev" {
|
||||||
os.Setenv("BEEGO_RUNMODE", runmode)
|
os.Setenv("BEEGO_RUNMODE", runmode)
|
||||||
|
2
test.go
2
test.go
@ -56,7 +56,7 @@ func testApp(cmd *Command, args []string) int {
|
|||||||
|
|
||||||
currpath, _ := os.Getwd()
|
currpath, _ := os.Getwd()
|
||||||
|
|
||||||
logger.Debugf("Current path: %s", currpath)
|
logger.Debugf("Current path: %s", __FILE__(), __LINE__(), currpath)
|
||||||
|
|
||||||
err := loadConfig()
|
err := loadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
12
util.go
12
util.go
@ -262,3 +262,15 @@ func IsDebugEnabled() bool {
|
|||||||
debugMode := os.Getenv("DEBUG_ENABLED")
|
debugMode := os.Getenv("DEBUG_ENABLED")
|
||||||
return map[string]bool{"1": true, "0": false}[debugMode]
|
return map[string]bool{"1": true, "0": false}[debugMode]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// __FILE__ returns the file name in which the function was invoked
|
||||||
|
func __FILE__() string {
|
||||||
|
_, file, _, _ := runtime.Caller(1)
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
// __LINE__ returns the line number at which the function was invoked
|
||||||
|
func __LINE__() int {
|
||||||
|
_, _, line, _ := runtime.Caller(1)
|
||||||
|
return line
|
||||||
|
}
|
||||||
|
5
watch.go
5
watch.go
@ -16,7 +16,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/howeyc/fsnotify"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -24,6 +23,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/howeyc/fsnotify"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -209,7 +210,7 @@ func Kill() {
|
|||||||
|
|
||||||
// Restart kills the running command process and starts it again
|
// Restart kills the running command process and starts it again
|
||||||
func Restart(appname string) {
|
func Restart(appname string) {
|
||||||
logger.Debugf("Kill running process")
|
logger.Debugf("Kill running process", __FILE__(), __LINE__())
|
||||||
Kill()
|
Kill()
|
||||||
go Start(appname)
|
go Start(appname)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user