godaemon/test/main.go

51 lines
844 B
Go
Raw Normal View History

2023-12-10 17:56:48 +08:00
package main
import (
"time"
"git.pyer.club/kingecg/godaemon"
"git.pyer.club/kingecg/gologger"
)
var daemon *godaemon.GoDaemon
func main() {
gologger.Configure(gologger.LoggersConfig{
Appenders: map[string]gologger.LogAppenderConfig{
"flog": {
2024-11-17 21:31:22 +08:00
Type: "console",
2023-12-10 17:56:48 +08:00
},
},
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)
2024-10-02 18:38:36 +08:00
l.Debug("task running:", g.GetPid())
2023-12-10 17:56:48 +08:00
}
}
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
}
2024-11-17 21:31:22 +08:00
2023-12-10 17:56:48 +08:00
}