You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An io.writer & io.Closer compliant file writer that will always write to the path that you give it, even if somebody deletes/renames that path out from under you.
Created so that Go programs can be used with the standard Linux logrotate: writes following a removal / rename will occur in a newly created file rather than the previously opened filehandle.
As the current implementation relies on remembering and checking the current inode of the desired file, this code will not work or compile on Windows.
Example
package main
import (
"github.com/mipearson/rfw""log"
)
funcmain() {
writer, err:=rfw.Open("/var/log/myprogram", 0644)
iferr!=nil {
log.Fatalln("Could not open '/var/log/myprogram': ", err)
}
log:=log.New(writer, "[myprogram] ", log.LstdFlags)
log.Println("Logging as normal")
}
TODO
Use exp/fsnotify so that we don't need to call stat on every write
Use exp/winfsnotify to allow for Windows support
Trap SIGHUP and close/reopen all files
Force a check every minute so that programs that rarely write can release filehandles