-
Notifications
You must be signed in to change notification settings - Fork 600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange behavior in truncate #143
Comments
It seems I needed to add call to _ , _ = file.Seek(0, 0) |
This doesn't work as well. r.GET("/logs/truncate", func(ctx *fasthttp.RequestCtx) {
file, err := os.OpenFile("file.log", os.O_CREATE|os.O_WRONLY, 0666)
if err == nil {
_ = file.Truncate(0)
_ , _ = file.Seek(0, io.SeekStart)
_, _ = fmt.Fprint(ctx, "success")
} else {
_, _ = fmt.Fprint(ctx, "error")
}
}) Although I have specified to rotate on 1500MB, still sometime it rotate the file say at 280MB then the issue with truncate start. |
You can't have other software fiddling with the file that lumberjack controls. Lumberjack needs to be the sole controller of the file. Lumberjack has an internal pointer to the file where it last wrote. If some outside process truncates the file, lumberjack doesn't know that, and will continue to write to the last place on disk where it thinks it should be writing. I'm not sure why you'd use cron to truncate the file if you're using lumberjack to rotate it. Pick one or the other. They can't both work. |
Yes, as I mentioned I now truncate the file using the url based route which is called by the cron every 15 minute. |
Well, I have been using it since quite a sometime but I have got new requirement of generating a file containing a few comma separated value.
I truncate it every 15 minute using cron, it worked for few days but lately I am getting strange issue of file getting to old size after app starts writing in it after truncating. So if at time of truncate file size was 700MB, it get truncated by cron but when app start writing again in it after few second, it start with 700MB with head -n1 file.log failing to show any output. nor vim works on file,
Only tail -f file.log work confirming that its being written at the last, but sure what is the issue with the start/head of the file as it is not showing the output.
I am using it with
Zap Logger
I even tried to truncate file using the app itself by creating a custom url like this and calling it from with cron instead of bash command.
But this also doesn't worked, file size kept on increasing sometime.
I have this code on 3 server and this issue has been happening randomly on 2 server.
Though it has been mentioned in #25 and file itself about multi process write will result in improper behavior still What you think could be the issue here? Any workaround...?
Also is there way to rotate the file based on time instead of size?
The text was updated successfully, but these errors were encountered: