hupwriter

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2024 License: MIT Imports: 7 Imported by: 2

README

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

Documentation

Overview

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 you can create log files that can be used with log rotation management programs such as logrotate, newsyslog, or so.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HupWriter

type HupWriter struct {
	// contains filtered or unexported fields
}

HupWriter wraps os.File, and will close and reopen the file when a HUP signal is received.

func New

func New(name, pid string) (*HupWriter, error)

New creates a HupWriter with a file of name. It create PID file which records current process ID when pid is not empty.

func (*HupWriter) Close

func (h *HupWriter) Close() error

Close closes an underlying file, and stop to listening signals.

func (*HupWriter) Reopen added in v1.0.0

func (h *HupWriter) Reopen() error

Reopen closes the output file and reopens it.

func (*HupWriter) Write

func (h *HupWriter) Write(p []byte) (int, error)

Write writes data to an underlying file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL