mirror of
https://github.com/beego/bee.git
synced 2024-11-25 09:50:55 +00:00
1. Make logs for beego developer not for bee developer
2. Fix debug mode
This commit is contained in:
parent
6dce4df2cb
commit
abf2b4a4cb
@ -73,14 +73,14 @@ func NewWatcher(paths []string, files []string, isgenerate bool) {
|
||||
|
||||
mt := getFileModTime(e.Name)
|
||||
if t := eventTime[e.Name]; mt == t {
|
||||
beeLogger.Log.Infof(colors.Bold("Skipping: ")+"%s", e.String())
|
||||
beeLogger.Log.Hintf(colors.Bold("Skipping: ")+"%s", e.String())
|
||||
isBuild = false
|
||||
}
|
||||
|
||||
eventTime[e.Name] = mt
|
||||
|
||||
if isBuild {
|
||||
beeLogger.Log.Infof("Event fired: %s", e)
|
||||
beeLogger.Log.Hintf("Event fired: %s", e)
|
||||
go func() {
|
||||
// Wait 1s before autobuild until there is no file change.
|
||||
scheduleTime = time.Now().Add(1 * time.Second)
|
||||
@ -96,7 +96,7 @@ func NewWatcher(paths []string, files []string, isgenerate bool) {
|
||||
|
||||
beeLogger.Log.Info("Initializing watcher...")
|
||||
for _, path := range paths {
|
||||
beeLogger.Log.Infof(colors.Bold("Watching: ")+"%s", path)
|
||||
beeLogger.Log.Hintf(colors.Bold("Watching: ")+"%s", path)
|
||||
err = watcher.Add(path)
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("Failed to watch directory: %s", err)
|
||||
|
@ -30,14 +30,14 @@ import (
|
||||
var errInvalidLogLevel = errors.New("logger: invalid log level")
|
||||
|
||||
const (
|
||||
levelCritical = iota
|
||||
levelFatal
|
||||
levelSuccess
|
||||
levelHint
|
||||
levelDebug
|
||||
levelInfo
|
||||
levelWarn
|
||||
levelDebug = iota
|
||||
levelError
|
||||
levelFatal
|
||||
levelCritical
|
||||
levelSuccess
|
||||
levelWarn
|
||||
levelInfo
|
||||
levelHint
|
||||
)
|
||||
|
||||
var (
|
||||
@ -45,6 +45,9 @@ var (
|
||||
instance *BeeLogger
|
||||
once sync.Once
|
||||
)
|
||||
var debugMode = map[string]bool{"1": true, "0": false}[os.Getenv("DEBUG_ENABLED")]
|
||||
|
||||
var logLevel = levelInfo
|
||||
|
||||
// BeeLogger logs logging records to the specified io.Writer
|
||||
type BeeLogger struct {
|
||||
@ -164,6 +167,9 @@ func (l *BeeLogger) getColorLevel(level int) string {
|
||||
// mustLog logs the message according to the specified level and arguments.
|
||||
// It panics in case of an error.
|
||||
func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) {
|
||||
if level > logLevel {
|
||||
return
|
||||
}
|
||||
// Acquire the lock
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
@ -184,9 +190,9 @@ func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) {
|
||||
// mustLogDebug logs a debug message only if debug mode
|
||||
// is enabled. i.e. DEBUG_ENABLED="1"
|
||||
func (l *BeeLogger) mustLogDebug(message string, file string, line int, args ...interface{}) {
|
||||
//if !IsDebugEnabled() {
|
||||
// return
|
||||
//}
|
||||
if !debugMode {
|
||||
return
|
||||
}
|
||||
|
||||
// Change the output to Stderr
|
||||
l.SetOutput(os.Stderr)
|
||||
|
@ -241,12 +241,6 @@ func WriteToFile(filename, content string) {
|
||||
MustCheck(err)
|
||||
}
|
||||
|
||||
// IsDebugEnabled checks if DEBUG_ENABLED is set or not
|
||||
func IsDebugEnabled() bool {
|
||||
debugMode := os.Getenv("DEBUG_ENABLED")
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user