1
0
Fork 0

로거 레벨 지정

This commit is contained in:
Sangbum Kim 2017-09-11 01:49:54 +09:00
parent 53c8085aa9
commit 6054cc2f0f
3 changed files with 21 additions and 5 deletions

View File

@ -45,6 +45,7 @@ func (c *fanControl) StartControl() {
} }
}() }()
defer close(c.fanSpeedConsumer) defer close(c.fanSpeedConsumer)
defer log.Info("Fan control stopped")
log.Info("Fan control started") log.Info("Fan control started")
ticker := time.Tick(c.sampleDuration) ticker := time.Tick(c.sampleDuration)

20
main.go
View File

@ -13,14 +13,28 @@ import (
"amuz.es/src/infra/cpu_ctrl/processor" "amuz.es/src/infra/cpu_ctrl/processor"
"amuz.es/src/infra/cpu_ctrl/util" "amuz.es/src/infra/cpu_ctrl/util"
"amuz.es/src/infra/cpu_ctrl/consumer" "amuz.es/src/infra/cpu_ctrl/consumer"
"gopkg.in/alecthomas/kingpin.v2"
) )
var ( var (
app = kingpin.New("cpu_ctrl", "Interactive CPU fan controller").Author("Sangbum Kim")
verbose = app.Flag("verbose", "Enable verbose mode.").Short('v').Bool()
P = app.Flag("proportional-gain", "Set proportional gain value.").Short('p').Default("1.5").Float64()
I = app.Flag("integral-gain", "Set integral gain value.").Short('i').Default("0.3").Float64()
D = app.Flag("derivative-gain", "Set derivative gain value.").Short('d').Default("1.0").Float64()
SetPoint = app.Flag("set-point", "Set pointe tempeture").Short('t').Default("38.0").Float64()
log = logger.NewLogger("cpu_ctrl") log = logger.NewLogger("cpu_ctrl")
) )
func init() { func init() {
logger.InitLogger(true, "", &logger.Config{FileName: "Stderr"}) app.Version("0.3")
if _, err := app.Parse(os.Args[1:]); err != nil {
panic(err)
}
logger.InitLogger(*verbose, "", &logger.Config{FileName: "Stderr"})
setMaxProcs() setMaxProcs()
} }
@ -75,7 +89,7 @@ func main() {
handler = util.NewHandler() handler = util.NewHandler()
sampleDuration = time.Second sampleDuration = time.Second
) )
log.Info("Cpu fan controller v0.2") log.Infof("Cpu fan controller")
if processorCount == 0 { if processorCount == 0 {
handler.NotifyError(errors.New("cpu not found!")) handler.NotifyError(errors.New("cpu not found!"))
@ -86,7 +100,7 @@ func main() {
processors = make([]processor.Processor, 0, processorCount) processors = make([]processor.Processor, 0, processorCount)
for i := 0; i < processorCount; i++ { for i := 0; i < processorCount; i++ {
if info, err := processor.NewProcessorInfo(handler, i, sampleDuration, if info, err := processor.NewProcessorInfo(handler, i, sampleDuration,
1.5, 0.4, 2.0, 38.0, 0x64, 0x4, *P, *I, *D, *SetPoint, 0x64, 0x4,
nil, fanController.Consumer(), nil, fanController.Consumer(),
); );
err != nil { err != nil {

View File

@ -125,6 +125,7 @@ func (p *processor) StartMonitoring() {
tempeturePathGlob := path.Join(p.tempeturePath, "temp?_input") tempeturePathGlob := path.Join(p.tempeturePath, "temp?_input")
ticker := time.Tick(p.sampleDuration) ticker := time.Tick(p.sampleDuration)
defer log.Infof("Processor %d monitor stopped", p.id)
log.Infof("Processor %d monitor started with %s", p.id, p.sampleDuration) log.Infof("Processor %d monitor started with %s", p.id, p.sampleDuration)
for { for {
@ -147,7 +148,7 @@ func (p *processor) StartMonitoring() {
} }
} }
p.tempeture = highestTemp p.tempeture = highestTemp
log.Infof("processor %d : tempeture changed %f", p.id, highestTemp) log.Debugf("processor %d : tempeture changed %f", p.id, highestTemp)
} }
fanspeed = p.normalizeFanspeed(p.fanController.Update(highestTemp)) fanspeed = p.normalizeFanspeed(p.fanController.Update(highestTemp))
@ -162,7 +163,7 @@ func (p *processor) StartMonitoring() {
} }
} }
p.fanSpeed = fanspeed p.fanSpeed = fanspeed
log.Infof("processor %d : fan changed 0x%x", p.id, fanspeed) log.Debugf("processor %d : fan changed 0x%x", p.id, fanspeed)
} }
case <-p.handler.Done(): case <-p.handler.Done():
return return