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