Browse Source

pkg: use uber zap as default log

pull/1/head
miraclesu 8 years ago
parent
commit
6e76bbe8b4
  1. 19
      bin/node/server.go
  2. 19
      bin/web/server.go

19
bin/node/server.go

@ -4,7 +4,10 @@ package main
import ( import (
"flag" "flag"
"runtime" slog "log"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/shunfei/cronsun" "github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf" "github.com/shunfei/cronsun/conf"
@ -14,14 +17,20 @@ import (
) )
var ( var (
gomax = flag.Int("gomax", level = flag.Int("l", -2, "log level, -1:debug, -2:info, -3:warn, -4:error")
4, "GOMAXPROCS: the max number of operating system threads that can execute")
) )
func main() { func main() {
flag.Parse() flag.Parse()
//set cpu usage
runtime.GOMAXPROCS(*gomax) lcf := zap.NewDevelopmentConfig()
lcf.Level.SetLevel(zapcore.Level(*level))
lcf.Development = false
logger, err := lcf.Build()
if err != nil {
slog.Fatalln("new log err:", err.Error())
}
log.SetLogger(logger.Sugar())
if err := cronsun.Init(); err != nil { if err := cronsun.Init(); err != nil {
log.Errorf(err.Error()) log.Errorf(err.Error())

19
bin/web/server.go

@ -1,10 +1,14 @@
package main package main
import ( import (
"flag"
slog "log"
"net" "net"
"time" "time"
"github.com/cockroachdb/cmux" "github.com/cockroachdb/cmux"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/shunfei/cronsun" "github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf" "github.com/shunfei/cronsun/conf"
@ -13,7 +17,22 @@ import (
"github.com/shunfei/cronsun/web" "github.com/shunfei/cronsun/web"
) )
var (
level = flag.Int("l", -2, "log level, -1:debug, -2:info, -3:warn, -4:error")
)
func main() { func main() {
flag.Parse()
lcf := zap.NewDevelopmentConfig()
lcf.Level.SetLevel(zapcore.Level(*level))
lcf.Development = false
logger, err := lcf.Build()
if err != nil {
slog.Fatalln("new log err:", err.Error())
}
log.SetLogger(logger.Sugar())
if err := cronsun.Init(); err != nil { if err := cronsun.Init(); err != nil {
log.Errorf(err.Error()) log.Errorf(err.Error())
return return

Loading…
Cancel
Save