Changed error logging for upload-clean as well.
This commit is contained in:
parent
c85c6555e2
commit
33f69eaf44
@ -20,32 +20,22 @@ var version string
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
log.SetFlags(log.Llongfile)
|
||||||
|
|
||||||
if *showVersion {
|
if *showVersion {
|
||||||
fmt.Println("dwelling-upload-clean Ver. ", version, "\nCopyright (c) 2022,2023 Alexander \"Arav\" Andreev <me@arav.su>")
|
fmt.Println("dwelling-upload-clean Ver. ", version, "\nCopyright (c) 2022,2023 Alexander \"Arav\" Andreev <me@arav.su>")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := configuration.LoadConfiguration(*configPath)
|
logClean, err := logging.New(path.Join(os.Getenv("LOGS_DIRECTORY"), "clean.log"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln("failed to open clean logger:", 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)
|
|
||||||
}
|
}
|
||||||
defer logClean.Close()
|
defer logClean.Close()
|
||||||
|
|
||||||
uploadsDir, err := ioutil.ReadDir(config.Uploads.Directory)
|
uploadsDir, err := ioutil.ReadDir(config.Uploads.Directory)
|
||||||
if err != nil {
|
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
|
var deletedCount int64 = 0
|
||||||
@ -54,7 +44,7 @@ func main() {
|
|||||||
for _, entry := range uploadsDir {
|
for _, entry := range uploadsDir {
|
||||||
if time.Now().UTC().Sub(entry.ModTime().UTC()) >= time.Duration(config.Uploads.Limits.KeepForHours)*time.Hour {
|
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 {
|
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 {
|
} else {
|
||||||
deletedSize += entry.Size()
|
deletedSize += entry.Size()
|
||||||
deletedCount++
|
deletedCount++
|
||||||
@ -65,6 +55,6 @@ func main() {
|
|||||||
_, _, cFSz := utils.ConvertFileSize(deletedSize)
|
_, _, cFSz := utils.ConvertFileSize(deletedSize)
|
||||||
|
|
||||||
if deletedCount > 0 {
|
if deletedCount > 0 {
|
||||||
logClean.Printf("%d %s", deletedCount, cFSz)
|
logClean.Println(deletedCount, cFSz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user