func fanControl(cfg *config, mainLogger *syslog.Writer) { currTemp := getTemp() prevTemp := currTemp prevLvl := uint16(1) currLvl := getFanLevel(cfg, currTemp, prevTemp, prevLvl) for { if prevLvl != currLvl { setFanLevel(currLvl) mainLogger.Debug(fmt.Sprintf("Fan level changed: %d -> %d (%d -> %d)", prevLvl, currLvl, prevTemp, currTemp)) } else { mainLogger.Debug(fmt.Sprintf("Fan level remained: %d (%d -> %d)", currLvl, prevTemp, currTemp)) } time.Sleep(time.Second * time.Duration(cfg.pollInterval)) prevTemp = currTemp currTemp = getTemp() prevLvl = currLvl currLvl = getFanLevel(cfg, currTemp, prevTemp, prevLvl) } }
func newSyslogAdapter(w *syslog.Writer) *LoggingAdapter { return &LoggingAdapter{ Debugf: func(format string, v ...interface{}) { w.Debug(fmt.Sprintf(format, v...)) }, Infof: func(format string, v ...interface{}) { w.Info(fmt.Sprintf(format, v...)) }, Warnf: func(format string, v ...interface{}) { w.Warning(fmt.Sprintf(format, v...)) }, Errorf: func(format string, v ...interface{}) { w.Err(fmt.Sprintf(format, v...)) }, Fatalf: func(format string, v ...interface{}) { s := fmt.Sprintf(format, v...) w.Crit(s) os.Exit(1) }, Panicf: func(format string, v ...interface{}) { s := fmt.Sprintf(format, v...) w.Emerg(s) panic(s) }, } }