logfile

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package logfile provides Ether's on-disk logs: a size-rotated log file (stderr is discarded under a Windows service and unrotated under launchd) and the crash log that receives fatal runtime traces.

Index

Constants

View Source
const (
	CrashLogName = "crash.log"

	// DefaultCrashMaxSize caps crash.log; larger logs are moved to
	// crash.log.1 at startup.
	DefaultCrashMaxSize int64 = 5 << 20
)

Crash log file names inside the logs directory.

View Source
const (
	DefaultMaxSize int64 = 10 << 20 // rotate at 10 MiB
	DefaultKeep          = 5        // ether.log.1 … ether.log.5
)

Defaults for the main log file.

Variables

This section is empty.

Functions

func Tee

func Tee(ws ...io.Writer) io.Writer

Tee returns a writer that writes to every w, ignoring individual failures (unlike io.MultiWriter, which stops at the first). Under a Windows service stderr is invalid; the file must still get every line.

Types

type CrashLog

type CrashLog struct {
	// File is open for appending; hand it to debug.SetCrashOutput (which
	// duplicates the descriptor) and then close it.
	File *os.File
	// Path is the crash log path.
	Path string
	// Changed reports that the crash log was written since the previous
	// start, i.e. the previous run died with a fatal error.
	Changed bool
}

CrashLog is the result of PrepareCrashLog.

func PrepareCrashLog

func PrepareCrashLog(dir string, maxSize int64) (*CrashLog, error)

PrepareCrashLog opens <dir>/crash.log for appending, rotating it to crash.log.1 first when it exceeds maxSize (<= 0: DefaultCrashMaxSize), and reports whether it changed since the previous call (tracked by a marker file touched on every call).

type Writer

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

Writer is a concurrency-safe io.Writer that appends to a file and rotates it by size: path -> path.1 -> … -> path.<keep>, dropping the oldest. A failed open or write closes the file and the next Write reopens it, so a transient error (disk full, file removed) does not disable logging for the rest of the process.

func Open

func Open(path string, maxSize int64, keep int) (*Writer, error)

Open creates the directory if needed and opens path for appending. maxSize <= 0 uses DefaultMaxSize; keep < 0 uses DefaultKeep (0 keeps no rotated files: the log is truncated at maxSize).

func (*Writer) Close

func (w *Writer) Close() error

Close closes the current file. Later writes reopen it.

func (*Writer) Path

func (w *Writer) Path() string

Path is the active log file.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write appends p, rotating first when p would push the file past maxSize. A single write is never split across files.

Jump to

Keyboard shortcuts

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