package main

import (
	"time"

	"git.kingecg.top/kingecg/godaemon"
	"git.kingecg.top/kingecg/gologger"
)

var daemon *godaemon.GoDaemon

func main() {
	gologger.Configure(gologger.LoggersConfig{
		Appenders: map[string]gologger.LogAppenderConfig{
			"flog": {
				Type: "console",
			},
		},
		Categories: map[string]gologger.LogConfig{
			"default": {
				Appenders: []string{"flog"},
				Level:     "debug",
			},
		},
	})
	daemon := godaemon.NewGoDaemon(start, stop)
	daemon.Start()
}

func start(g *godaemon.GoDaemon) {
	l := gologger.GetLogger("task")
	for {
		time.Sleep(time.Second * 1)
		l.Debug("task running:", g.GetPid())
	}
}

func stop(g *godaemon.GoDaemon) {
	l := gologger.GetLogger("task")
	l.Debug("called stop")
	if g == nil {
		l.Debug("Daemon is nil")
		return
	}
	if g.Running == nil {
		l.Debug("task is nil")
		return
	}

}
