set.go 940 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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"
)

func Set(name string,param *Param)error  {
	if _,has:=logNames[name];!has{
		return fmt.Errorf("not has that log config of %s",name)
	}
	c:=new(entity.LogConfig)
	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
	}else{
		c.Enable = 0
	}
	c.Fields = param.Fields
	c.Expire = param.Expire
	err :=dao.Set(c)
	if err!=nil{
		return err
	}
	_=dao2.UpdateTable("goku_config_log")

	if name == ConsoleLog{
		go reset(c)
	}
	return nil
}
func reset(c *entity.LogConfig)  {

	period,_:=log.ParsePeriod(c.Period)
	log.SetOutPut(c.Enable == 1,c.Dir,c.File,period,c.Expire)
	l,_:= log.ParseLevel(c.Level)
	log.SetLevel(l)

}