diff --git a/common/config.go b/common/config.go index 663d23c..4b236bc 100644 --- a/common/config.go +++ b/common/config.go @@ -3,7 +3,6 @@ package common import ( "github.com/fsnotify/fsnotify" "github.com/spf13/viper" - "log" "os" "sendmsg/global" "sendmsg/model" @@ -21,7 +20,7 @@ func InitConfig() (model.Config, error) { viper.AddConfigPath("../config") viper.AddConfigPath(workDir + "/config") viper.OnConfigChange(func(e fsnotify.Event) { - log.Printf("[conf] config update: %v\n", e.Name) + Log.Printf("[conf] config update: %v\n", e.Name) global.GLO_CONF_CH <- updateConfig() }) viper.WatchConfig() diff --git a/main.go b/main.go index 243ba47..935bab6 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "log" "sendmsg/common" "sendmsg/global" "sendmsg/message" @@ -18,7 +17,7 @@ func init() { global.GLO_CONF_CH = make(chan model.Config) _conf, err := common.InitConfig() if err != nil { - log.Fatalf("[init] Failed to initialize config: %v", err) + common.Log.Fatalf("[init] Failed to initialize config: %v", err) } global.GLO_CONF = _conf } diff --git a/message/bark.go b/message/bark.go index 47fba97..fbfce90 100644 --- a/message/bark.go +++ b/message/bark.go @@ -3,8 +3,8 @@ package message import ( "bytes" "encoding/json" - "log" "net/http" + "sendmsg/common" "sendmsg/model" ) @@ -14,7 +14,7 @@ type Bark struct { } func (b *Bark) Send(body Body) { - log.Printf("[bark] sending message...") + common.Log.Printf("[bark] sending message...") var reqBody = model.BarkRequest{ DeviceKey: b.key, Title: body.Title, @@ -25,9 +25,9 @@ func (b *Bark) Send(body Body) { "application/json; charset=utf-8", bytes.NewReader(req)) if err != nil { - log.Fatalf("[bark] http post failed: %v\n", err) + common.Log.Fatalf("[bark] http post failed: %v\n", err) } defer resp.Body.Close() - log.Printf("[bark] Send successful") + common.Log.Printf("[bark] Send successful") } diff --git a/message/mail.go b/message/mail.go index 518d152..003b7a7 100644 --- a/message/mail.go +++ b/message/mail.go @@ -3,8 +3,8 @@ package message import ( "fmt" "github.com/jordan-wright/email" - "log" "net/smtp" + "sendmsg/common" ) type Mail struct { @@ -18,7 +18,7 @@ type Mail struct { } func (m *Mail) Send(body Body) { - log.Printf("[mail] sending message...") + common.Log.Printf("[mail] sending message...") e := email.NewEmail() e.From = m.FromName e.To = m.To @@ -27,7 +27,7 @@ func (m *Mail) Send(body Body) { addr := fmt.Sprintf("%v:%v", m.Host, m.Port) err := e.Send(addr, smtp.PlainAuth("", m.Username, m.Password, m.Host)) if err != nil { - log.Fatalf("[mail] send failed: %v\n", err) + common.Log.Fatalf("[mail] send failed: %v\n", err) } - log.Printf("[mail] send successful") + common.Log.Printf("[mail] send successful") } diff --git a/message/message_test.go b/message/message_test.go index 393a5c5..14e1766 100644 --- a/message/message_test.go +++ b/message/message_test.go @@ -1,7 +1,6 @@ package message import ( - "log" "sendmsg/common" "sendmsg/global" "testing" @@ -11,7 +10,7 @@ import ( func TestSend(t *testing.T) { conf, err := common.InitConfig() if err != nil { - log.Println("[test] Failed to initialize config: ", err) + common.Log.Println("[test] Failed to initialize config: ", err) } global.GLO_CONF = conf diff --git a/service/service.go b/service/service.go index ca47142..317e50e 100644 --- a/service/service.go +++ b/service/service.go @@ -1,7 +1,7 @@ package service import ( - "log" + "sendmsg/common" "sendmsg/message" ) @@ -10,7 +10,7 @@ type Service struct { } func (s Service) Run() { - log.Printf("[service] start excute...") + common.Log.Printf("[service] start excute...") send(s.Body) }