Rotating File Writer

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
Owner
Similar Resources

Rotating cache for small data with lock-free access.

Rotating cache Byte cache implementation with lock-free access. Designed to work with small data under high pressure. Lock-free access (both read and

Dec 5, 2021

Rotate is a tool for rotating out AWS Auto-Scaling Groups within a k8s cluster

k8s-r8 rotate is a tool for rotating out AWS Auto-Scaling Groups within a k8s cluster. It was developed to make upgrading AMIs as a one command experi

Mar 27, 2022

GoLang - Produces a binary suitable for use in shell scripts and cron jobs for rotating IAM credentials.

AWS-Rotate-IAM-Key aws-rotate-iam-key makes it easy to rotate your IAM keys whether they be in your ~/.aws/credentials file or else where. This work i

Feb 9, 2022

Cheap/fast/simple XLSX file writer for textual data

xlsxwriter Cheap/fast/simple XLSX file writer for textual data -- no fancy formatting or graphs go get github.com/mzimmerman/xlsxwriter data := [][]s

Feb 8, 2022

This is a simple file storage server. User can upload file, delete file and list file on the server.

This is a simple file storage server.  User can upload file,  delete file and list file on the server.

Simple File Storage Server This is a simple file storage server. User can upload file, delete file and list file on the server. If you want to build a

Jan 19, 2022

go-colorable - Colorable writer for windows.

go-colorable - Colorable writer for windows.

go-colorable Colorable writer for windows. For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But

Dec 30, 2022

Highly concurrent drop-in replacement for bufio.Writer

concurrent-writer Highly concurrent drop-in replacement for bufio.Writer. concurrent.Writer implements highly concurrent buffering for an io.Writer ob

Nov 20, 2022

Rolling writer is an IO util for auto rolling write in go.

RollingWriter RollingWriter is an auto rotate io.Writer implementation. It can works well with logger. Awesome Go popular log helper New Version v2.0

Dec 20, 2022

Optimized bit-level Reader and Writer for Go.

bitio Package bitio provides an optimized bit-level Reader and Writer for Go. You can use Reader.ReadBits() to read arbitrary number of bits from an i

Dec 1, 2022

A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

one-file-pdf - A minimalist PDF generator in 2K lines and 1 file The main idea behind this project was: "How small can I make a PDF generator for it

Dec 11, 2022

go-colorable - Colorable writer for Windows

go-colorable - Colorable writer for Windows

go-colorable Colorable writer for windows. For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But

Dec 21, 2022

gensvg generates SVG to an io.Writer

gensvg generates SVG to an io.Writer

gensvg: A Go library for SVG generation The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification

Dec 28, 2022

Golang io.Reader and io.Writer but with limits

LimitIO io.Reader and io.Writer with limit.

Dec 14, 2022

csv reader/writer.

IO csv reader sample version 0.0.1-SNAPSHOT Goals: main: read huge file, hex substring, write to new file. cmd/v2 version can read and write use ony o

Nov 4, 2021

csv reader/writer and csv generator.

IO csv reader sample version 0.0.1-SNAPSHOT Goals: main: read huge file, hex substring, write to new file. repo has 2 version. v1 can read a file and

Nov 4, 2021

Simple binary reader and writer

Simple binary reader and writer

Simple Binary Stream Reader/Writer This package contains a set of simple utility reader and writer that can be used to efficiently read/write binary i

Oct 30, 2022

A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type.

writehasher A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type. Example package main import ( "fmt"

Jan 10, 2022

A feature flag solution, with only a YAML file in the backend (S3, GitHub, HTTP, local file ...), no server to install, just add a file in a central system and refer to it. 🎛️

A feature flag solution, with only a YAML file in the backend (S3, GitHub, HTTP, local file ...), no server to install, just add a file in a central system and refer to it. 🎛️

🎛️ go-feature-flag A feature flag solution, with YAML file in the backend (S3, GitHub, HTTP, local file ...). No server to install, just add a file i

Dec 29, 2022

Convert scanned image PDF file to text annotated PDF file

Convert scanned image PDF file to text annotated PDF file

Jisui (自炊) This tool is PoC (Proof of Concept). Jisui is a helper tool to create e-book. Ordinary the scanned book have not text information, so you c

Dec 11, 2022
Comments
  • updates rfw.go to always typecast checkInode()'s result to uint64

    updates rfw.go to always typecast checkInode()'s result to uint64

    On FreeBSD, the syscall 'stat' returns an uint32 which results in this during cross compilation: github.com/mipearson/rfw/rfw.go:65: cannot use stat.Ino (type uint32) as type uint64 in return argument

  • `undefined: syscall.Stat_t` Error on windows7

    `undefined: syscall.Stat_t` Error on windows7

    Hi, @mipearson When I run

    go get github.com/mipearson/rfw
    

    on windows 7 64bit. it occured:

    GOPATH\src\github.com\mipearson\rfw\rfw.go:63: undefined: syscall.Stat_t
    GOPATH\src\github.com\mipearson\rfw\rfw.go:64: undefined: syscall.Stat
    

    OS: windows7 64bit go version go1.7.3 windows/amd64

A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Dec 14, 2022
Rolling writer is an IO util for auto rolling write in go.

RollingWriter RollingWriter is an auto rotate io.Writer implementation. It can works well with logger. Awesome Go popular log helper New Version v2.0

Dec 20, 2022
Parse awesome-go README file and generate a new README file with repo info.

Awesome Go Extra All data are from awesome-go and GitHub API. Audio and Music Libraries for manipulating audio. Name Description Star Open Issues Crea

Aug 11, 2022
Port of perl5 File::RotateLogs to Go

file-rotatelogs Provide an io.Writer that periodically rotates log files from within the application. Port of File::RotateLogs from Perl to Go. SYNOPS

Jan 9, 2023
A hack example to servce file as a webserver with a Google Cloud Functions

Overview This project is a hack example to servce file as a webserver with a Google Cloud Functions (normally single purpose, only one entry point). I

Nov 26, 2021
Goimportcycle - a tool to visualize Go imports resolved to the file level
Goimportcycle - a tool to visualize Go imports resolved to the file level

Go Import Cycle goimportcycle is a tool to visualize Go imports resolved to the

Dec 8, 2022
Filez - A tiny package showing you File info

filez A tiny package showing you File info Install go get -v github.com/Cne3Rd/f

Feb 4, 2022
The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.
The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.

Static Go Playground Features Full Go Compiler running on the browser. Supports using custom build tags. Incremental builds (build cache). Supports mu

Jun 16, 2022
Rotating File Writer

Rotating File writer An io.writer & io.Closer compliant file writer that will always write to the path that you give it, even if somebody deletes/rena

Jul 12, 2021
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Dec 14, 2022