Skip to content

mipearson/rfw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rotating File writer

wercker status GoDoc

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"
)

func main() {
  writer, err := rfw.Open("/var/log/myprogram", 0644)
  if err != 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

About

Rotating File Writer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages