1
0

Changed error logging for upload-clean as well.

This commit is contained in:
Alexander Andreev 2023-05-24 22:09:04 +04:00
parent c85c6555e2
commit 33f69eaf44
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -20,32 +20,22 @@ var version string
func main() {
flag.Parse()
log.SetFlags(log.Llongfile)
if *showVersion {
fmt.Println("dwelling-upload-clean Ver. ", version, "\nCopyright (c) 2022,2023 Alexander \"Arav\" Andreev <me@arav.su>")
return
}
config, err := configuration.LoadConfiguration(*configPath)
logClean, err := logging.New(path.Join(os.Getenv("LOGS_DIRECTORY"), "clean.log"))
if err != nil {
log.Fatalln(err)
}
logErr, err := logging.New(config.Log.CleanError)
if err != nil {
log.Fatalln("failed to open error logger:", err)
}
defer logErr.Close()
logClean, err := logging.New(config.Log.Clean)
if err != nil {
log.Fatalln("failed to open error logger:", err)
log.Fatalln("failed to open clean logger:", err)
}
defer logClean.Close()
uploadsDir, err := ioutil.ReadDir(config.Uploads.Directory)
if err != nil {
logErr.Fatalf("failed to open directory %s: %s\n", config.Uploads.Directory, err)
log.Fatalf("failed to open directory %s: %s\n", *uploadDir, err)
}
var deletedCount int64 = 0
@ -54,7 +44,7 @@ func main() {
for _, entry := range uploadsDir {
if time.Now().UTC().Sub(entry.ModTime().UTC()) >= time.Duration(config.Uploads.Limits.KeepForHours)*time.Hour {
if err := os.Remove(path.Join(config.Uploads.Directory, entry.Name())); err != nil {
logErr.Println("failed to remove file ", entry.Name(), ": ", err)
log.Printf("failed to remove file %s: %s", entry.Name(), err)
} else {
deletedSize += entry.Size()
deletedCount++
@ -65,6 +55,6 @@ func main() {
_, _, cFSz := utils.ConvertFileSize(deletedSize)
if deletedCount > 0 {
logClean.Printf("%d %s", deletedCount, cFSz)
logClean.Println(deletedCount, cFSz)
}
}