修改 log pre

This commit is contained in:
dengsgo 2019-01-19 17:10:07 +08:00
parent 433ea136e4
commit 8e99507ff4
3 changed files with 21 additions and 18 deletions

View File

@ -15,6 +15,9 @@ import (
const (
Version = 1
PreError = "ERROR:"
PreWarn = "Warn:"
)
var (
@ -37,14 +40,14 @@ func parseConfig() {
cfg = new(FileGirl)
fc, err := ioutil.ReadFile(projectFolder + "/filegirl.yaml")
if err != nil {
log.Panicln("read filegirl.yaml file err: ", err)
log.Panicln(PreError, "read filegirl.yaml file err: ", err)
}
err = yaml.Unmarshal(fc, cfg)
if err != nil {
log.Panicln("parsed filegirl.yaml failed: ", err)
log.Panicln(PreError, "parsed filegirl.yaml failed: ", err)
}
if cfg.Core.Version > Version {
log.Panicln("current fileboy support max version : ", Version)
log.Panicln(PreError, "current fileboy support max version : ", Version)
}
log.Println(cfg)
}
@ -78,10 +81,10 @@ func addWatcher() {
for i := 0; i < len(cfg.Monitor.IncludeDirs); i++ {
darr := dirParse2Array(cfg.Monitor.IncludeDirs[i])
if len(darr) < 1 || len(darr) > 2 {
log.Fatalln("filegirl section monitor dirs is error. ", cfg.Monitor.IncludeDirs[i])
log.Fatalln(PreError, "filegirl section monitor dirs is error. ", cfg.Monitor.IncludeDirs[i])
}
if strings.HasPrefix(darr[0], "/") {
log.Fatalln("dirs must be relative paths ! err path:", cfg.Monitor.IncludeDirs[i])
log.Fatalln(PreError, "dirs must be relative paths ! err path:", cfg.Monitor.IncludeDirs[i])
}
if darr[0] == "." {
if len(darr) == 2 && darr[1] == "*" {
@ -147,7 +150,7 @@ func initWatcher() {
if !ok {
return
}
log.Println("error:", err)
log.Println(PreError, err)
}
}
}()
@ -160,7 +163,7 @@ func parseArgs() {
if l == 1 {
_, err := ioutil.ReadFile(projectFolder + "/filegirl.yaml")
if err != nil {
log.Println("the filegirl.yaml file does not exist! ", err)
log.Println(PreError, "the filegirl.yaml file does not exist! ", err)
fmt.Print(firstRunHelp)
return
}
@ -173,7 +176,7 @@ func parseArgs() {
case "init":
err := ioutil.WriteFile(projectFolder+"/filegirl.yaml", []byte(exampleFileGirl), 0644)
if err != nil {
log.Println("error create filegirl.yaml config! ", err)
log.Println(PreError, "error create filegirl.yaml config! ", err)
return
}
log.Println("create filegirl.yaml ok")

View File

@ -34,7 +34,7 @@ func newNetNotifier(callUrl string) *NetNotifier {
func (n *NetNotifier) Put(cf *changedFile) {
if !n.CanPost {
log.Println("notifier call url ignore. ", n.CallUrl)
log.Println(PreWarn, "notifier call url ignore. ", n.CallUrl)
return
}
n.dispatch(&postParams{
@ -48,7 +48,7 @@ func (n *NetNotifier) Put(cf *changedFile) {
func (n *NetNotifier) dispatch(params *postParams) {
b, err := json.Marshal(params)
if err != nil {
log.Println("error: json.Marshal n.params. ", err)
log.Println(PreError, "json.Marshal n.params. ", err)
return
}
client := &http.Client{
@ -56,14 +56,14 @@ func (n *NetNotifier) dispatch(params *postParams) {
}
req, err := http.NewRequest("POST", n.CallUrl, bytes.NewBuffer(b))
if err != nil {
log.Println("error: http.NewRequest. ", err)
log.Println(PreError, "http.NewRequest. ", err)
return
}
req.Header.Set("Content-Type", "application/json;charset=UTF-8")
req.Header.Set("User-Agent", "FileBoy Net Notifier v1.5")
resp, err := client.Do(req)
if err != nil {
log.Println("notifier call failed. err:", err)
log.Println(PreError, "notifier call failed. err:", err)
return
}
defer func() {

View File

@ -46,11 +46,11 @@ func (t *TaskMan) Put(cf *changedFile) {
func (t *TaskMan) preRun(cf *changedFile) {
if t.cmd != nil && t.cmd.Process != nil {
log.Println("stop old process ")
err := t.cmd.Process.Kill()
if err != nil {
log.Println("err: ", err)
log.Println(PreWarn, "stopped err, reason:", err)
}
log.Println("stop old process ")
}
go t.run(cf)
}
@ -71,12 +71,12 @@ func (t *TaskMan) run(cf *changedFile) {
t.cmd.Env = os.Environ()
stdout, err := t.cmd.StdoutPipe()
if err != nil {
log.Println("error=>", err.Error())
log.Println(PreError, err.Error())
return
}
err = t.cmd.Start()
if err != nil {
log.Println("run command", carr, "error. ", err)
log.Println(PreError, "run command", carr, "error. ", err)
}
reader := bufio.NewReader(stdout)
for {
@ -88,12 +88,12 @@ func (t *TaskMan) run(cf *changedFile) {
}
err = t.cmd.Wait()
if err != nil {
log.Println("cmd wait err ", err)
log.Println(PreWarn, "cmd wait err ", err)
break
}
if t.cmd.Process != nil {
if err = t.cmd.Process.Kill(); err != nil {
log.Println("cmd cannot kill ", err)
log.Println(PreWarn, "cmd cannot kill, reason:", err)
}
}
}