Implementing the new logging infrastructure

Moved logging to the new logging infrastructure by removing the use of
ColorLog() function. Added more documentation. Also fixed some typos in
comments and function names.
This commit is contained in:
Faissal Elamraoui
2016-11-13 15:14:48 +01:00
parent 0e54238559
commit cf7aef47f0
26 changed files with 421 additions and 525 deletions

34
run.go
View File

@ -15,7 +15,6 @@
package main
import (
"fmt"
"io/ioutil"
"os"
path "path/filepath"
@ -77,9 +76,8 @@ func runApp(cmd *Command, args []string) int {
appname = path.Base(currpath)
currentGoPath = _gopath
} else {
exitPrint(fmt.Sprintf("Bee does not support non Beego project: %s", currpath))
logger.Fatalf("No Beego application '%s' found in your GOPATH", currpath)
}
ColorLog("[INFO] Using '%s' as 'appname'\n", appname)
} else {
// Check if passed Bee application path/name exists in the GOPATH(s)
if found, _gopath, _path := SearchGOPATHs(args[0]); found {
@ -87,35 +85,35 @@ func runApp(cmd *Command, args []string) int {
currentGoPath = _gopath
appname = path.Base(currpath)
} else {
exitPrint(fmt.Sprintf("No Beego application '%s' found in your GOPATH", args[0]))
logger.Fatalf("No Beego application '%s' found in your GOPATH", args[0])
}
ColorLog("[INFO] Using '%s' as 'appname'\n", appname)
if strings.HasSuffix(appname, ".go") && isExist(currpath) {
ColorLog("[WARN] The appname is in conflict with currpath's file, do you want to build appname as %s\n", appname)
ColorLog("[INFO] Do you want to overwrite it? [yes|no]] ")
logger.Warnf("The appname is in conflict with file's current path. Do you want to build appname as '%s'", appname)
logger.Info("Do you want to overwrite it? [yes|no] ")
if !askForConfirmation() {
return 0
}
}
}
Debugf("current path:%s\n", currpath)
logger.Infof("Using '%s' as 'appname'", appname)
logger.Debugf("Current path: %s", currpath)
if runmode == "prod" || runmode == "dev" {
os.Setenv("BEEGO_RUNMODE", runmode)
ColorLog("[INFO] Using '%s' as 'runmode'\n", os.Getenv("BEEGO_RUNMODE"))
logger.Infof("Using '%s' as 'runmode'", os.Getenv("BEEGO_RUNMODE"))
} else if runmode != "" {
os.Setenv("BEEGO_RUNMODE", runmode)
ColorLog("[WARN] Using '%s' as 'runmode'\n", os.Getenv("BEEGO_RUNMODE"))
logger.Warnf("Using '%s' as 'runmode'", os.Getenv("BEEGO_RUNMODE"))
} else if os.Getenv("BEEGO_RUNMODE") != "" {
ColorLog("[WARN] Using '%s' as 'runmode'\n", os.Getenv("BEEGO_RUNMODE"))
logger.Warnf("Using '%s' as 'runmode'", os.Getenv("BEEGO_RUNMODE"))
}
err := loadConfig()
if err != nil {
ColorLog("[ERRO] Failed to load configuration [ %s ]\n", err)
logger.Fatalf("Failed to load configuration: %s", err)
}
var paths []string
@ -143,10 +141,10 @@ func runApp(cmd *Command, args []string) int {
}
if gendoc == "true" {
NewWatcher(paths, files, true)
Autobuild(files, true)
AutoBuild(files, true)
} else {
NewWatcher(paths, files, false)
Autobuild(files, false)
AutoBuild(files, false)
}
for {
@ -202,16 +200,16 @@ func isExcluded(filePath string) bool {
for _, p := range excludedPaths {
absP, err := path.Abs(p)
if err != nil {
ColorLog("[ERROR] Can not get absolute path of [ %s ]\n", p)
logger.Errorf("Cannot get absolute path of '%s'", p)
continue
}
absFilePath, err := path.Abs(filePath)
if err != nil {
ColorLog("[ERROR] Can not get absolute path of [ %s ]\n", filePath)
logger.Errorf("Cannot get absolute path of '%s'", filePath)
break
}
if strings.HasPrefix(absFilePath, absP) {
ColorLog("[INFO] Excluding from watching [ %s ]\n", filePath)
logger.Infof("'%s' is not being watched", filePath)
return true
}
}