优化 log
This commit is contained in:
parent
b6be235c6e
commit
d2be0654e2
22
fileboy.go
22
fileboy.go
@ -43,16 +43,14 @@ func parseConfig() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(PreError, "the filegirl.yaml file in", projectFolder, "is not exist! ", err)
|
log.Println(PreError, "the filegirl.yaml file in", projectFolder, "is not exist! ", err)
|
||||||
fmt.Print(firstRunHelp)
|
fmt.Print(firstRunHelp)
|
||||||
log.Fatalln("fileboy unable to run.")
|
logAndExit("fileboy unable to run.")
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal(fc, cfg)
|
err = yaml.Unmarshal(fc, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(PreError, "parsed filegirl.yaml failed: ", err)
|
logAndExit(PreError, "parsed filegirl.yaml failed: ", err)
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
if cfg.Core.Version > Version {
|
if cfg.Core.Version > Version {
|
||||||
log.Println(PreError, "current fileboy support max version : ", Version)
|
logAndExit(PreError, "current fileboy support max version : ", Version)
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
// init map
|
// init map
|
||||||
cfg.Monitor.TypesMap = map[string]bool{}
|
cfg.Monitor.TypesMap = map[string]bool{}
|
||||||
@ -95,10 +93,10 @@ func addWatcher() {
|
|||||||
for _, dir := range cfg.Monitor.IncludeDirs {
|
for _, dir := range cfg.Monitor.IncludeDirs {
|
||||||
darr := dirParse2Array(dir)
|
darr := dirParse2Array(dir)
|
||||||
if len(darr) < 1 || len(darr) > 2 {
|
if len(darr) < 1 || len(darr) > 2 {
|
||||||
log.Fatalln(PreError, "filegirl section monitor dirs is error. ", dir)
|
logAndExit(PreError, "filegirl section monitor dirs is error. ", dir)
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(darr[0], "/") {
|
if strings.HasPrefix(darr[0], "/") {
|
||||||
log.Fatalln(PreError, "dirs must be relative paths ! err path:", dir)
|
logAndExit(PreError, "dirs must be relative paths ! err path:", dir)
|
||||||
}
|
}
|
||||||
if darr[0] == "." {
|
if darr[0] == "." {
|
||||||
if len(darr) == 2 && darr[1] == "*" {
|
if len(darr) == 2 && darr[1] == "*" {
|
||||||
@ -126,7 +124,7 @@ func addWatcher() {
|
|||||||
}
|
}
|
||||||
for _, dir := range cfg.Monitor.ExceptDirs {
|
for _, dir := range cfg.Monitor.ExceptDirs {
|
||||||
if dir == "." {
|
if dir == "." {
|
||||||
log.Fatalln(PreError, "exceptDirs must is not project root path ! err path:", dir)
|
logAndExit(PreError, "exceptDirs must is not project root path ! err path:", dir)
|
||||||
}
|
}
|
||||||
p := projectFolder + "/" + dir
|
p := projectFolder + "/" + dir
|
||||||
delete(dirsMap, p)
|
delete(dirsMap, p)
|
||||||
@ -138,7 +136,7 @@ func addWatcher() {
|
|||||||
log.Println("watcher add -> ", dir)
|
log.Println("watcher add -> ", dir)
|
||||||
err := watcher.Add(dir)
|
err := watcher.Add(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
logAndExit(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println("total monitored dirs: " + strconv.Itoa(len(dirsMap)))
|
log.Println("total monitored dirs: " + strconv.Itoa(len(dirsMap)))
|
||||||
@ -153,7 +151,7 @@ func initWatcher() {
|
|||||||
}
|
}
|
||||||
watcher, err = fsnotify.NewWatcher()
|
watcher, err = fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
logAndExit(err)
|
||||||
}
|
}
|
||||||
taskMan = newTaskMan(cfg.Command.DelayMillSecond, cfg.Notifier.CallUrl)
|
taskMan = newTaskMan(cfg.Command.DelayMillSecond, cfg.Notifier.CallUrl)
|
||||||
go func() {
|
go func() {
|
||||||
@ -206,7 +204,7 @@ func parseArgs() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
log.Fatalln("Unknown parameters, use `fileboy help` show help info.")
|
logAndExit("Unknown parameters, use `fileboy help` show help info.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +223,7 @@ func main() {
|
|||||||
var err error
|
var err error
|
||||||
projectFolder, err = os.Getwd()
|
projectFolder, err = os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
logAndExit(err)
|
||||||
}
|
}
|
||||||
parseArgs()
|
parseArgs()
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (t *TaskMan) run(cf *changedFile) {
|
|||||||
log.Println(PreWarn, "cmd wait err ", err)
|
log.Println(PreWarn, "cmd wait err ", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if t.cmd.Process != nil && t.cmd.ProcessState != nil && !t.cmd.ProcessState.Exited() {
|
if t.cmd.Process != nil {
|
||||||
if err = t.cmd.Process.Kill(); err != nil {
|
if err = t.cmd.Process.Kill(); err != nil {
|
||||||
log.Println(PreWarn, "cmd cannot kill, reason:", err)
|
log.Println(PreWarn, "cmd cannot kill, reason:", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user