airobot/main.go
2022-12-09 18:41:12 +08:00

60 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"io"
"os"
"fyne.io/fyne/v2/app"
"github.com/sirupsen/logrus"
"legu.airobot/busi/friend"
"legu.airobot/lib"
"legu.airobot/theme"
)
func init() {
var err error
if err = setupLogger(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func main() {
app := app.NewWithID("aiRobot")
app.SetIcon(theme.ResourceAppPng)
a := lib.NewAI()
a.InitCaller(
&friend.FriendRecommend{Desc: "好友推荐"},
&friend.FriendApply{Desc: "好友申请"},
)
}
func setupLogger() (err error) {
logrus.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05",
// DisableColors: true,
// FullTimestamp: true,
})
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(os.Stdout)
//设置output,默认为stderr,可以为任何io.Writer比如文件*os.File
file, err := os.OpenFile("robot.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
writers := []io.Writer{
file,
os.Stdout}
//同时写文件和屏幕
fileAndStdoutWriter := io.MultiWriter(writers...)
if err == nil {
logrus.SetOutput(fileAndStdoutWriter)
} else {
logrus.Fatal("failed to log to file.")
}
return nil
}