set.go 966 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10
package config_log

import (
	"fmt"
	log "github.com/eolinker/goku/goku-log"
	dao2 "github.com/eolinker/goku/server/dao"
	dao "github.com/eolinker/goku/server/dao/config-log"
	entity "github.com/eolinker/goku/server/entity/config-log"
)

Y
Your Name 已提交
11 12 13
func Set(name string, param *Param) error {
	if _, has := logNames[name]; !has {
		return fmt.Errorf("not has that log config of %s", name)
E
eoLinker API Management 已提交
14
	}
Y
Your Name 已提交
15
	c := new(entity.LogConfig)
E
eoLinker API Management 已提交
16 17 18 19 20 21 22 23
	c.Name = name
	c.Level = param.Level

	c.Period = param.Period
	c.File = param.File
	c.Dir = param.Dir
	if param.Enable {
		c.Enable = 1
Y
Your Name 已提交
24
	} else {
E
eoLinker API Management 已提交
25 26 27 28
		c.Enable = 0
	}
	c.Fields = param.Fields
	c.Expire = param.Expire
Y
Your Name 已提交
29 30
	err := dao.Set(c)
	if err != nil {
E
eoLinker API Management 已提交
31 32
		return err
	}
Y
Your Name 已提交
33
	_ = dao2.UpdateTable("goku_config_log")
E
eoLinker API Management 已提交
34

Y
Your Name 已提交
35
	if name == ConsoleLog {
E
eoLinker API Management 已提交
36 37 38 39
		go reset(c)
	}
	return nil
}
Y
Your Name 已提交
40
func reset(c *entity.LogConfig) {
E
eoLinker API Management 已提交
41

Y
Your Name 已提交
42 43 44
	period, _ := log.ParsePeriod(c.Period)
	log.SetOutPut(c.Enable == 1, c.Dir, c.File, period, c.Expire)
	l, _ := log.ParseLevel(c.Level)
E
eoLinker API Management 已提交
45 46
	log.SetLevel(l)

Y
Your Name 已提交
47
}