file

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package file is a logging sink that writes records to a file as JSON lines, rotating it by size:

file.New(file.Options{Path: "logs/app.log", MaxSize: 50 << 20, Keep: 10})

A rotated file is renamed with the time it was rotated, app-20261111T150405.123.log, and gzipped if Compress is set; the oldest beyond Keep are removed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Path is the file written to. Its directory is created if need be.
	Path string
	// MaxSize is the size in bytes at which the file is rotated. The
	// default is 100 MiB; -1 never rotates.
	MaxSize int64
	// Keep is how many rotated files are kept. The default is 7; -1 keeps
	// them all.
	Keep int
	// Compress gzips rotated files.
	Compress bool
	// Mode is the new files' permissions. The default is 0o640.
	Mode os.FileMode
}

Options configures the sink.

type Sink

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

Sink writes to a file. Make one with New; Close it to close the file (logging.Close does).

func New

func New(o Options) *Sink

New returns a file sink. The file is opened on the first write.

func (*Sink) Close

func (s *Sink) Close() error

Close flushes and closes the file.

func (*Sink) Export

func (s *Sink) Export(_ context.Context, entries []logging.Entry) error

Export implements logging.Sink.

func (*Sink) Name

func (s *Sink) Name() string

Name implements the name logging reports errors with.

Jump to

Keyboard shortcuts

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