package main
import (
"fmt"
"io"
"os"
"time"
)
func main() {
defer func() {
err := recover()
if err != nil {
logrus.Info(err)
}
}()
log_path := "runtime/logs/"
_, err := os.Stat(log_path)
if err != nil {
if os.IsNotExist(err) {
err = os.MkdirAll(log_path, 0755)
if err != nil {
logrus.Fatal("目录创建错误", err)
}
}
}
log_file := log_path + "error" + time.Now().Format("2006-01-02") + ".log"
fd, err := os.OpenFile(log_file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
logrus.Info("打开文件错误", err)
return
}
logrus.SetOutput(io.MultiWriter(os.Stdout, fd))
Test(1, 0)
}
func Test(x int, y int) {
a := x / y
fmt.Println(a)
}