Browse Source

log sending email error

haiswork 5 years ago
parent
commit
f08364b404
1 changed files with 10 additions and 3 deletions
  1. 10
    3
      service/service.go

+ 10
- 3
service/service.go View File

2
 
2
 
3
 import (
3
 import (
4
 	"fmt"
4
 	"fmt"
5
+	"log"
5
 	"net/http"
6
 	"net/http"
6
 	"strings"
7
 	"strings"
7
 	"time"
8
 	"time"
30
 		err := monitorURL(url)
31
 		err := monitorURL(url)
31
 		if cache.CheckMonitor(url, err) {
32
 		if cache.CheckMonitor(url, err) {
32
 			if err != nil {
33
 			if err != nil {
33
-				notice.SendEmailBySMTP("url error", config.C.Notice.Emails, err.Error(), false)
34
+				err = notice.SendEmailBySMTP(url+" timeout", config.C.Notice.Emails, err.Error(), false)
34
 			} else {
35
 			} else {
35
-				notice.SendEmailBySMTP("url return ok", config.C.Notice.Emails, "return ok", false)
36
+				err = notice.SendEmailBySMTP(url+" ok", config.C.Notice.Emails, "ok", false)
37
+			}
38
+			if err != nil {
39
+				log.Printf("send email error:%s,host:%s", err.Error(), config.C.Notice.SMTP.Host)
36
 			}
40
 			}
37
 		}
41
 		}
38
 	}
42
 	}
50
 	}
54
 	}
51
 	useTime := int64(time.Now().Sub(startTime) / time.Millisecond)
55
 	useTime := int64(time.Now().Sub(startTime) / time.Millisecond)
52
 	if useTime > config.C.Monitor.Timeout {
56
 	if useTime > config.C.Monitor.Timeout {
53
-		return fmt.Errorf("timeout url:%s,millisecond:%d", url, useTime)
57
+		return fmt.Errorf("url:%s timeout:%dms", url, useTime)
58
+	}
59
+	if config.C.App.Debug {
60
+		log.Printf("url:%s use time:%dms\n", url, useTime)
54
 	}
61
 	}
55
 	return nil
62
 	return nil
56
 }
63
 }