mirror of
https://github.com/casbin/bee.git
synced 2025-07-17 04:03:24 +08:00
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:
35
pack.go
35
pack.go
@ -104,11 +104,6 @@ func init() {
|
||||
w = NewColorWriter(os.Stdout)
|
||||
}
|
||||
|
||||
func exitPrint(con string) {
|
||||
fmt.Fprintln(os.Stderr, con)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
type walker interface {
|
||||
isExclude(string) bool
|
||||
isEmpty(string) bool
|
||||
@ -397,10 +392,10 @@ func (wft *zipWalk) compress(name, fpath string, fi os.FileInfo) (bool, error) {
|
||||
func packDirectory(excludePrefix []string, excludeSuffix []string,
|
||||
excludeRegexp []*regexp.Regexp, includePath ...string) (err error) {
|
||||
|
||||
ColorLog("Excluding relpath prefix: %s\n", strings.Join(excludePrefix, ":"))
|
||||
ColorLog("Excluding relpath suffix: %s\n", strings.Join(excludeSuffix, ":"))
|
||||
logger.Infof("Excluding relpath prefix: %s", strings.Join(excludePrefix, ":"))
|
||||
logger.Infof("Excluding relpath suffix: %s", strings.Join(excludeSuffix, ":"))
|
||||
if len(excludeRegexp) > 0 {
|
||||
ColorLog("Excluding filename regex: `%s`\n", strings.Join(excludeR, "`, `"))
|
||||
logger.Infof("Excluding filename regex: `%s`", strings.Join(excludeR, "`, `"))
|
||||
}
|
||||
|
||||
w, err := os.OpenFile(outputP, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
@ -477,17 +472,17 @@ func packApp(cmd *Command, args []string) int {
|
||||
|
||||
thePath, err := path.Abs(appPath)
|
||||
if err != nil {
|
||||
exitPrint(fmt.Sprintf("Wrong app path: %s", thePath))
|
||||
logger.Fatalf("Wrong application path: %s", thePath)
|
||||
}
|
||||
if stat, err := os.Stat(thePath); os.IsNotExist(err) || stat.IsDir() == false {
|
||||
exitPrint(fmt.Sprintf("App path does not exist: %s", thePath))
|
||||
logger.Fatalf("Application path does not exist: %s", thePath)
|
||||
}
|
||||
|
||||
if isBeegoProject(thePath) == false {
|
||||
exitPrint(fmt.Sprintf("Bee does not support non Beego project"))
|
||||
logger.Fatal("Bee does not support non Beego project")
|
||||
}
|
||||
|
||||
ColorLog("Packaging application: %s\n", thePath)
|
||||
logger.Infof("Packaging application on '%s'...", thePath)
|
||||
|
||||
appName := path.Base(thePath)
|
||||
|
||||
@ -507,7 +502,7 @@ func packApp(cmd *Command, args []string) int {
|
||||
os.Mkdir(tmpdir, 0700)
|
||||
|
||||
if build {
|
||||
ColorLog("Building application...\n")
|
||||
logger.Info("Building application...")
|
||||
var envs []string
|
||||
for _, env := range buildEnvs {
|
||||
parts := strings.SplitN(env, "=", 2)
|
||||
@ -529,7 +524,7 @@ func packApp(cmd *Command, args []string) int {
|
||||
os.Setenv("GOOS", goos)
|
||||
os.Setenv("GOARCH", goarch)
|
||||
|
||||
ColorLog("Env: GOOS=%s GOARCH=%s\n", goos, goarch)
|
||||
logger.Infof("Using: GOOS=%s GOARCH=%s", goos, goarch)
|
||||
|
||||
binPath := path.Join(tmpdir, appName)
|
||||
if goos == "windows" {
|
||||
@ -552,10 +547,10 @@ func packApp(cmd *Command, args []string) int {
|
||||
execmd.Dir = thePath
|
||||
err = execmd.Run()
|
||||
if err != nil {
|
||||
exitPrint(err.Error())
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
|
||||
ColorLog("Build successful\n")
|
||||
logger.Success("Build successful!")
|
||||
}
|
||||
|
||||
switch format {
|
||||
@ -573,7 +568,7 @@ func packApp(cmd *Command, args []string) int {
|
||||
if _, err := os.Stat(outputP); err != nil {
|
||||
err = os.MkdirAll(outputP, 0755)
|
||||
if err != nil {
|
||||
exitPrint(err.Error())
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@ -595,7 +590,7 @@ func packApp(cmd *Command, args []string) int {
|
||||
for _, r := range excludeR {
|
||||
if len(r) > 0 {
|
||||
if re, err := regexp.Compile(r); err != nil {
|
||||
exitPrint(err.Error())
|
||||
logger.Fatal(err.Error())
|
||||
} else {
|
||||
exr = append(exr, re)
|
||||
}
|
||||
@ -604,9 +599,9 @@ func packApp(cmd *Command, args []string) int {
|
||||
|
||||
err = packDirectory(exp, exs, exr, tmpdir, thePath)
|
||||
if err != nil {
|
||||
exitPrint(err.Error())
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
|
||||
ColorLog("Writing to output: `%s`\n", outputP)
|
||||
logger.Infof("Writing to output: %s", outputP)
|
||||
return 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user