pkg: remove sunteng log

pull/1/head
miraclesu 8 years ago
parent dcc1c421eb
commit b1e95b07bf

@ -6,11 +6,10 @@ import (
"flag"
"runtime"
"sunteng/commons/log"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/event"
"github.com/shunfei/cronsun/log"
"github.com/shunfei/cronsun/node"
)
@ -25,18 +24,18 @@ func main() {
runtime.GOMAXPROCS(*gomax)
if err := cronsun.Init(); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
n, err := node.NewNode(conf.Config)
if err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
if err = n.Register(); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
@ -45,11 +44,11 @@ func main() {
}
if err = n.Run(); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
log.Noticef("cronsun %s service started, Ctrl+C or send kill sign to exit", n.String())
log.Infof("cronsun %s service started, Ctrl+C or send kill sign to exit", n.String())
// 注册退出事件
event.On(event.EXIT, n.Stop, conf.Exit, cronsun.Exit)
// 注册监听配置更新事件
@ -58,5 +57,5 @@ func main() {
event.Wait()
// 处理退出事件
event.Emit(event.EXIT, nil)
log.Notice("exit success")
log.Infof("exit success")
}

@ -6,23 +6,22 @@ import (
"github.com/cockroachdb/cmux"
"sunteng/commons/log"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/event"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/log"
"github.com/shunfei/cronsun/web"
)
func main() {
if err := cronsun.Init(); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
l, err := net.Listen("tcp", conf.Config.Web.BindAddr)
if err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
@ -31,7 +30,7 @@ func main() {
httpL := m.Match(cmux.HTTP1Fast())
httpServer, err := web.InitRouters()
if err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
@ -43,7 +42,7 @@ func main() {
} else {
mailer, err := cronsun.NewMail(10 * time.Second)
if err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
return
}
noticer = mailer
@ -60,11 +59,11 @@ func main() {
go m.Serve()
log.Noticef("cronsun web server started on %s, Ctrl+C or send kill sign to exit", conf.Config.Web.BindAddr)
log.Infof("cronsun web server started on %s, Ctrl+C or send kill sign to exit", conf.Config.Web.BindAddr)
// 注册退出事件
event.On(event.EXIT, conf.Exit)
// 监听退出信号
event.Wait()
event.Emit(event.EXIT, nil)
log.Notice("exit success")
log.Infof("exit success")
}

@ -9,10 +9,9 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/go-gomail/gomail"
"sunteng/commons/log"
"github.com/shunfei/cronsun/event"
"github.com/shunfei/cronsun/db"
"github.com/shunfei/cronsun/event"
"github.com/shunfei/cronsun/log"
"github.com/shunfei/cronsun/utils"
)
@ -64,7 +63,6 @@ type Conf struct {
// 默认 300
LockTtl int64
Log *log.Config
Etcd client.Config
Mgo *db.Config
Web webConfig
@ -136,7 +134,6 @@ func (c *Conf) parse() error {
} else {
c.Mgo.Timeout *= time.Second
}
log.InitConf(c.Log)
c.Node = cleanKeyPrefix(c.Node)
c.Proc = cleanKeyPrefix(c.Proc)
@ -193,7 +190,7 @@ func (c *Conf) watch() error {
func (c *Conf) reload() {
cf := new(Conf)
if err := cf.parse(); err != nil {
log.Warn("config file reload err:", err.Error())
log.Warnf("config file reload err: %s", err.Error())
return
}
@ -201,7 +198,7 @@ func (c *Conf) reload() {
cf.Node, cf.Proc, cf.Cmd, cf.Once, cf.Lock, cf.Group, cf.Noticer = c.Node, c.Proc, c.Cmd, c.Once, c.Lock, c.Group, c.Noticer
*c = *cf
log.Noticef("config file[%s] reload success", *confFile)
log.Infof("config file[%s] reload success", *confFile)
return
}

@ -17,7 +17,6 @@
"ProcReq": 5,
"#LockTtl": "任务锁最大过期时间,单位秒,默认 600",
"LockTtl": 600,
"Log": "@extend:log.json",
"Etcd": "@extend:etcd.json",
"Mgo": "@extend:db.json",
"Mail": "@extend:mail.json",

@ -1,15 +0,0 @@
{
"Appenders":{
"Node":{
"Type":"file",
"Target":"/data/logs/cronsun/node.log"
},
"stdout":{
"Type":"console"
}
},
"Root":{
"Level":"DEBUG",
"Appenders":["stdout", "Node"]
}
}

@ -8,8 +8,8 @@ import (
client "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc/mvccpb"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
)
// 结点类型分组

@ -18,8 +18,8 @@ import (
client "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc/mvccpb"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
"github.com/shunfei/cronsun/node/cron"
)
@ -244,13 +244,13 @@ func (c *Cmd) lock() *locker {
resp, err := DefalutClient.Grant(lk.ttl)
if err != nil {
log.Noticef("job[%s] didn't get a lock, err: %s", c.Job.Key(), err.Error())
log.Infof("job[%s] didn't get a lock, err: %s", c.Job.Key(), err.Error())
return nil
}
ok, err := DefalutClient.GetLock(c.Job.ID, resp.ID)
if err != nil {
log.Noticef("job[%s] didn't get a lock, err: %s", c.Job.Key(), err.Error())
log.Infof("job[%s] didn't get a lock, err: %s", c.Job.Key(), err.Error())
return nil
}

@ -6,7 +6,7 @@ import (
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"sunteng/commons/log"
"github.com/shunfei/cronsun/log"
)
const (
@ -103,7 +103,7 @@ func CreateJobLog(j *Job, t time.Time, rs string, success bool) {
EndTime: et,
}
if err := mgoDB.Insert(Coll_JobLog, jl); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
}
latestLog := &JobLatestLog{
@ -112,7 +112,7 @@ func CreateJobLog(j *Job, t time.Time, rs string, success bool) {
}
latestLog.Id = ""
if err := mgoDB.Upsert(Coll_JobLatestLog, bson.M{"node": jl.Node, "jobId": jl.JobId, "jobGroup": jl.JobGroup}, latestLog); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
}
var inc = bson.M{"total": 1}
@ -124,11 +124,11 @@ func CreateJobLog(j *Job, t time.Time, rs string, success bool) {
err := mgoDB.Upsert(Coll_Stat, bson.M{"name": "job-day", "date": time.Now().Format("2006-01-02")}, bson.M{"$inc": inc})
if err != nil {
log.Error("increase stat.job ", err.Error())
log.Errorf("increase stat.job %s", err.Error())
}
err = mgoDB.Upsert(Coll_Stat, bson.M{"name": "job"}, bson.M{"$inc": inc})
if err != nil {
log.Error("increase stat.job ", err.Error())
log.Errorf("increase stat.job %s", err.Error())
}
}

@ -0,0 +1,40 @@
package log
var (
DefaultLogger Logger
)
type Logger interface {
Debugf(format string, v ...interface{})
Infof(format string, v ...interface{})
Warnf(format string, v ...interface{})
Errorf(format string, v ...interface{})
}
func SetLogger(l Logger) {
DefaultLogger = l
}
func Debugf(format string, v ...interface{}) {
if DefaultLogger != nil {
DefaultLogger.Debugf(format, v...)
}
}
func Infof(format string, v ...interface{}) {
if DefaultLogger != nil {
DefaultLogger.Infof(format, v...)
}
}
func Warnf(format string, v ...interface{}) {
if DefaultLogger != nil {
DefaultLogger.Warnf(format, v...)
}
}
func Errorf(format string, v ...interface{}) {
if DefaultLogger != nil {
DefaultLogger.Errorf(format, v...)
}
}

@ -9,11 +9,11 @@ import (
"time"
client "github.com/coreos/etcd/clientv3"
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
)
const (
@ -129,7 +129,7 @@ func WatchNode() client.WatchChan {
func (n *Node) On() {
n.Alived, n.Version, n.UpTime = true, Version, time.Now()
if err := mgoDB.Upsert(Coll_Node, bson.M{"_id": n.ID}, n); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
}
}
@ -137,6 +137,6 @@ func (n *Node) On() {
func (n *Node) Down() {
n.Alived, n.DownTime = false, time.Now()
if err := mgoDB.Upsert(Coll_Node, bson.M{"_id": n.ID}, n); err != nil {
log.Error(err.Error())
log.Errorf(err.Error())
}
}

@ -47,7 +47,7 @@ func TestRange(t *testing.T) {
t.Errorf("%s => expected %v, got %v", c.expr, c.err, err)
}
if len(c.err) == 0 && err != nil {
t.Error("%s => unexpected error %v", c.expr, err)
t.Errorf("%s => unexpected error %v", c.expr, err)
}
if actual != c.expected {
t.Errorf("%s => expected %d, got %d", c.expr, c.expected, actual)

@ -8,10 +8,9 @@ import (
client "github.com/coreos/etcd/clientv3"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
"github.com/shunfei/cronsun/node/cron"
"github.com/shunfei/cronsun/utils"
)
@ -112,7 +111,7 @@ func (n *Node) keepAlive() {
if err := n.set(); err != nil {
log.Warnf("%s set lid err: %s, try to reset after %d seconds...", n.String(), err.Error(), n.ttl)
} else {
log.Noticef("%s set lid[%x] success", n.String(), n.lID)
log.Infof("%s set lid[%x] success", n.String(), n.lID)
}
timer.Reset(duration)
}
@ -225,7 +224,7 @@ func (n *Node) addCmd(cmd *cronsun.Cmd, notice bool) {
}
if notice {
log.Noticef("job[%s] rule[%s] timer[%s] has added", c.Job.ID, c.JobRule.ID, c.JobRule.Timer)
log.Infof("job[%s] rule[%s] timer[%s] has added", c.Job.ID, c.JobRule.ID, c.JobRule.Timer)
}
return
}
@ -233,7 +232,7 @@ func (n *Node) addCmd(cmd *cronsun.Cmd, notice bool) {
func (n *Node) delCmd(cmd *cronsun.Cmd) {
delete(n.cmds, cmd.GetID())
n.Cron.DelJob(cmd)
log.Noticef("job[%s] rule[%s] timer[%s] has deleted", cmd.Job.ID, cmd.JobRule.ID, cmd.JobRule.Timer)
log.Infof("job[%s] rule[%s] timer[%s] has deleted", cmd.Job.ID, cmd.JobRule.ID, cmd.JobRule.Timer)
}
func (n *Node) addGroup(g *cronsun.Group) {

@ -11,8 +11,8 @@ import (
client "github.com/coreos/etcd/clientv3"
"github.com/go-gomail/gomail"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
)
type Noticer interface {

@ -2,15 +2,15 @@ package cronsun
import (
"fmt"
"strings"
"sync"
"sync/atomic"
"time"
client "github.com/coreos/etcd/clientv3"
"strings"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
)
var (
@ -115,7 +115,7 @@ func (l *leaseID) keepAlive() {
if err := l.set(); err != nil {
log.Warnf("proc lease id set err: %s, try to reset after %d seconds...", err.Error(), l.ttl)
} else {
log.Noticef("proc set lease id[%x] success", l.get())
log.Infof("proc set lease id[%x] success", l.get())
}
timer.Reset(duration)
}

@ -10,7 +10,7 @@ import (
"strings"
"time"
"sunteng/commons/log"
"github.com/shunfei/cronsun/log"
)
type BaseHandler struct {

@ -6,15 +6,15 @@ import (
v3 "github.com/coreos/etcd/clientv3"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
)
type Info struct{}
func (inf *Info) Overview(w http.ResponseWriter, r *http.Request) {
var overview = struct {
TotalJobs int64 `json:"totalJobs"`
TotalJobs int64 `json:"totalJobs"`
JobExecuted *cronsun.StatExecuted `json:"jobExecuted"`
JobExecutedDaily *cronsun.StatExecuted `json:"jobExecutedDaily"`
}{}

@ -5,14 +5,14 @@ import (
"net/http"
"sort"
"strings"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/gorilla/mux"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun"
"time"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
)
type Job struct{}
@ -206,7 +206,7 @@ func (j *Job) GetList(w http.ResponseWriter, r *http.Request) {
m, err := cronsun.GetJobLatestLogListByJobIds(jobIds)
if err != nil {
log.Error("GetJobLatestLogListByJobIds error:", err.Error())
log.Errorf("GetJobLatestLogListByJobIds error: %s", err.Error())
} else {
for i := range jobList {
jobList[i].LatestStatus = m[jobList[i].ID]
@ -289,7 +289,7 @@ func (j *Job) GetExecutingJob(w http.ResponseWriter, r *http.Request) {
for i := range gresp.Kvs {
proc, err := cronsun.GetProcFromKey(string(gresp.Kvs[i].Key))
if err != nil {
log.Error("Failed to unmarshal Proc from key: ", err.Error())
log.Errorf("Failed to unmarshal Proc from key: %s", err.Error())
continue
}

@ -1,6 +1,7 @@
package web
import (
"math"
"net/http"
"strings"
"time"
@ -9,7 +10,6 @@ import (
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"math"
"github.com/shunfei/cronsun"
)
@ -89,7 +89,7 @@ func (jl *JobLog) GetList(w http.ResponseWriter, r *http.Request) {
}
var pager struct {
Total int `json:"total"`
Total int `json:"total"`
List []*cronsun.JobLog `json:"list"`
}
var err error

@ -2,16 +2,16 @@ package web
import (
"encoding/json"
"fmt"
"net/http"
"strings"
v3 "github.com/coreos/etcd/clientv3"
"github.com/gorilla/mux"
"fmt"
"sunteng/commons/log"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
)
type Node struct{}
@ -92,7 +92,7 @@ func (n *Node) DeleteGroup(w http.ResponseWriter, r *http.Request) {
gresp, err := cronsun.DefalutClient.Get(conf.Config.Cmd, v3.WithPrefix())
if err != nil {
errstr := fmt.Sprintf("failed to fetch jobs from etcd after deleted node group[%s]: %s", groupId, err.Error())
log.Error(errstr)
log.Errorf(errstr)
outJSONWithCode(w, http.StatusInternalServerError, errstr)
return
}

@ -6,8 +6,8 @@ import (
"github.com/gorilla/mux"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
)
func GetVersion(w http.ResponseWriter, r *http.Request) {

Loading…
Cancel
Save