koron / hupwriter

HUP acceptable io.Writer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HUP acceptable io.Writer

PkgGoDev Actions/Go Go Report Card

Package hupwriter provides wrapper of os.File.

The wrapper will close and reopen the file when a HUP signal is received. It allows easier log file rotation.

By logging to hupwriter.HupWriter you can create log files that can be used with log rotation management programs such as logrotate, newsyslog, or so.

Getting Started

Install and Upgrade

$ go get github.com/koron/hupwriter@latest

Usage

import (
    "github.com/koron/hupwriter"
    "log"
)

h := hupwriter.New("/var/log/myapp.log", "/var/pid/myapp.pid")
log.SetOutput(h)

// TODO: log something.
## Rename the log file to rotate
# mv /var/log/myapp.log /var/log/myapp.0

## Send HUP signal to the process. It closes and reopens myapp.log file.
# kill -HUP $(cat /var/pid/myapp.pid)

## (OPTIONAL) Compress rotated log file
# gzip /var/log/myapp.0

About

HUP acceptable io.Writer

License:MIT License


Languages

Language:Go 91.7%Language:Makefile 8.3%