master
Evan Chen 2021-12-19 18:52:40 +08:00
parent c276c276c4
commit 93c09aa414
8 changed files with 18 additions and 12 deletions

View File

@ -9,7 +9,7 @@ import (
func Error() *History {
h := getBase()
h.Type = ERROR
if !PROD {
if !util.PROD {
h.Trace = util.Stack()
}
return h

View File

@ -12,8 +12,6 @@ import (
"kumoly.io/kumoly/app/store"
)
var PROD = false
const (
ERROR = "ERROR"
INFO = "INFO"

View File

@ -2,7 +2,6 @@ package history
import (
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"kumoly.io/kumoly/app/store"
)
@ -14,7 +13,6 @@ func (srv Service) IsService() bool { return true }
func (srv Service) GetDependencies() []string { return []string{"server.Service"} }
func (srv Service) Init() error {
PROD = viper.GetBool("prod")
l := log.With().Str("mod", "history").
Str("service", "history.Service").
Logger()

View File

@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"kumoly.io/kumoly/app/errors"
"kumoly.io/kumoly/app/util"
)
func (srv *Service) Default(c *gin.Context) {
@ -31,6 +32,9 @@ func (srv *Service) Default(c *gin.Context) {
c.Abort()
cl.Str("error", fmt.Sprint(err))
}
if !util.PROD {
cl.Str("trace", util.Stack())
}
} else if c.Writer.Status() >= 400 {
cl = srv.l.Error().Strs("error", c.Errors.Errors())
} else {

View File

@ -27,7 +27,7 @@ func init() {
viper.SetDefault("domain", "kumoly.io")
viper.SetDefault("timezone", "Asia/Taipei")
// mode [prod, dev]
viper.SetDefault("prod", PROD)
viper.SetDefault("prod", true)
// log.level : [-1(trace):5(panic)] 7 to disable
viper.SetDefault("log.level", int(zerolog.InfoLevel))
@ -50,7 +50,8 @@ func Setup() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerolog.DurationFieldInteger = true
zerolog.SetGlobalLevel(zerolog.Level(viper.GetInt("log.level")))
if !viper.GetBool("prod") {
util.PROD = viper.GetBool("prod")
if util.PROD {
log.Logger = log.With().Caller().Logger()
}
if viper.GetBool("log.pretty") {

View File

@ -11,9 +11,9 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"kumoly.io/kumoly/app/history"
"kumoly.io/kumoly/app/util"
)
var PROD = true
var l zerolog.Logger
func init() {
@ -77,7 +77,7 @@ func (sys *System) order() {
for i := range nodes {
sys.services = append(sys.services, *nodes[i].srv)
}
if !PROD {
if !util.PROD {
seq := ""
for i := range sys.services {
seq += sys.services[i].GetName()

View File

@ -61,9 +61,12 @@ func (t *_task) Run() {
}
defer func() {
if err := recover(); err != nil {
l.Error().Str("task_id", t.Task.ID).
Str("task_name", t.name).Str("trace", util.Stack()).
Str("error", fmt.Sprint(err)).Msg("task paniced")
le := l.Error().Str("task_id", t.Task.ID).Str("task_name", t.name).
Str("error", fmt.Sprint(err))
if !util.PROD {
le.Str("trace", util.Stack())
}
le.Msg("task paniced")
} else if t.once {
c.Remove(t.id)

View File

@ -5,6 +5,8 @@ import (
"path/filepath"
)
var PROD bool = true
func Mkdir(args ...interface{}) error {
var path string
var mode os.FileMode