feat: add log

main
ZGGSONG 2 years ago
parent 5cff81ee50
commit 5c4085f29e

@ -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()

@ -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
}

@ -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")
}

@ -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")
}

@ -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

@ -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)
}

Loading…
Cancel
Save