Replies: 4 comments
-
Log rotation and cleanup is handled externally in every server software, from Nginx to Redis. There's logrotate for Unix, there are plenty of equivalents for Windows. Just remember to use the |
Beta Was this translation helpful? Give feedback.
-
The problem is on windows the log file is in use (and locked) by the server executable. We don't want to have to close the server to move/copy or delete the file. How do you suggest we handle this on windows? |
Beta Was this translation helpful? Give feedback.
-
Hello, i checked the Windows implementation, and is true that rtsp-simple-server locks the log files. This is the default behavior offered by Golang. There is surely a way to avoid this, since other servers for Windows allows to move / delete log files. I need to investigate further. |
Beta Was this translation helpful? Give feedback.
-
i investigated deeper; while it's not possible to move or delete the file, it's possible to copy it on another location and truncate it (like i suggested before, the package main
import (
"os"
"io/ioutil"
"strconv"
)
var logfile = "rtsp-simple-server.log"
func copyFile(source, dest string) error {
byts, err := ioutil.ReadFile(source)
if err != nil {
return err
}
return ioutil.WriteFile(dest, byts, 0644)
}
func main() {
i := 1
for {
_, err := os.Stat(logfile+"."+strconv.FormatInt(int64(i), 10))
if err != nil {
break
}
i++
}
for j := i-1; j >= 1; j-- {
err := os.Rename(logfile+"."+strconv.FormatInt(int64(j), 10), logfile+"."+strconv.FormatInt(int64(j+1), 10))
if err != nil {
panic(err)
}
}
err := copyFile(logfile, logfile+".1")
if err != nil {
panic(err)
}
err = os.Truncate(logfile, 0)
if err != nil {
panic(err)
}
} (PS: On Windows, it's possible to write to files without locking them, but in this way the server would write logs to the moved/deleted file, and not to a newer one, therefore it's better not to enable this feature) |
Beta Was this translation helpful? Give feedback.
-
Which version are you using?
v0.15.0
Enhancement request
Would it be possible to add a feature to set the max log file size? The issue is that if the log gets too big over time it could fill up the drive.
Possibly 2 settings:
Beta Was this translation helpful? Give feedback.
All reactions