log_windows.go 622 Bytes
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
//go:build windows
// +build windows

package mylogrus

import (
	"os"
	"path/filepath"
	"time"
)

func RewriteStderrFile() {
	filename := logDir + filepath.Base(os.Args[0]) + ".stderr.log"
	if exits, _ := pathExists(filename); exits {
		os.Rename(filename, filename+"_"+time.Now().Format("20060102150405"))
	}

	file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	MyLog.Errorf("stderr log in:%v,err:%v", file, err)
}

func pathExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}