1 Star 0 Fork 0

德尔软件部/go日志库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
log_cleaner.go 960 Bytes
一键复制 编辑 原始数据 按行查看 历史
张金富 提交于 2021-07-20 09:03 +08:00 . first
// 根据指定过期时间自动清除归档日志目录中的数据,过期时间单位为天。
package mylog
import (
"fmt"
"time"
gfile "github.com/gogf/gf/os/gfile"
"github.com/gogf/gf/os/gtime"
)
const (
AUTO_CHECK_INTERVAL = 3600 // (秒)自动检测时间间隔
)
var LogExpire = 30
func CleanLog() {
time.Sleep(time.Second)
go func() {
for {
cleanExpiredBackupFiles()
time.Sleep(AUTO_CHECK_INTERVAL * time.Second)
}
}()
}
func SetLogExpire(expire int) {
LogExpire = expire
}
// 清除过期的备份日志文件
func cleanExpiredBackupFiles() {
fmt.Println("clear log")
if list, err := gfile.ScanDir(LogPath, "*.log", true); err == nil {
for _, path := range list {
if gfile.IsFile(path) && gtime.Timestamp()-gfile.MTime(path).Unix() >= int64(LogExpire*86400) {
if err := gfile.Remove(path); err != nil {
Error(err)
} else {
Debug("removed file:", path)
}
}
}
} else {
Error(err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dell_software_department/mylog.git
git@gitee.com:dell_software_department/mylog.git
dell_software_department
mylog
go日志库
master

搜索帮助