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 (
"flag"
"runtime"
slog "log"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
@ -14,14 +17,20 @@ import (
)
var (
gomax = flag.Int("gomax",
4, "GOMAXPROCS: the max number of operating system threads that can execute")
level = flag.Int("l", -2, "log level, -1:debug, -2:info, -3:warn, -4:error")
)
func main() {
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 {
log.Errorf(err.Error())

19
bin/web/server.go

@ -1,10 +1,14 @@
package main
import (
"flag"
slog "log"
"net"
"time"
"github.com/cockroachdb/cmux"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
@ -13,7 +17,22 @@ import (
"github.com/shunfei/cronsun/web"
)
var (
level = flag.Int("l", -2, "log level, -1:debug, -2:info, -3:warn, -4:error")
)
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 {
log.Errorf(err.Error())
return

Loading…
Cancel
Save