logx

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logx holds where the log of the process goes and how a log file is written. The code writes its records through the log package of zerolog, whose logger writes to Out, and what a library writes through slog or the standard log package goes there too. Every record says where it comes from in its caller field

Index

Constants

View Source
const Told = "told"

Field a record carries as true when its words were said to the user on the terminal as it was written, such as a notice printed there: the files keep the record and the terminal never shows it, so the user reads the words once

Variables

View Source
var Out = start()

Where every record of the process's log goes: kept, and shown nowhere, until the logs host takes them and Route sends the records where that host writes them, the files and, as far as the settings say the terminal shows the log, the terminal. Drawn on the terminal that far once the host gave the sink back. A length of time in a record reads as time.Duration writes it

Functions

func Adopt

func Adopt(path string) error

Gives the file or folder at the path the owner of the folder it is in, when this process runs as root and that folder is another user's, so the user icebath runs as can write it later, as when icebath ran under sudo

func Capture

func Capture(path string, keep int) (*os.File, error)

The file a child that outlives this process writes its output to, appended to as its standard output and error: what the child before it wrote turned over first, as many kept as given, so what the last one said stays beside what this one says. Made as log files are: owner-only, its folder made when missing, the one above it never

func Console

func Console() zerolog.LevelWriter

Writer drawing each record on the terminal's error stream as a user reads it, from the level Show last said up and none before Show said one, without the place in the code it was written from, and never a record whose words the user was told there already

func Crashes

func Crashes(path string, size int64, keep int) error

Has the Go runtime write what it says as the process dies, a fatal error or a panic nothing recovered with the stacks of its goroutines, to the end of the file at the path as well as to the terminal's error stream: the file turned over first once it holds more than size bytes, with keep older ones kept, and made as log files are

func Foreign

func Foreign(path string) bool

Whether the file or folder at the path belongs to a user other than the one this process runs as, who then may not write it

func Note

func Note(path string, text []byte) error

Writes a whole report to a file of its own, such as the output of a failed step, made as log files are: owner-only, its folder made when missing, the one above it never, given the owner of its folder when this process runs as root

func Older

func Older(path string, keep int) []string

The files the log at the path turned over, the newest first, as far as they are there among the count kept

func Open

func Open(path string) (*os.File, error)

Opens the log file at the path to read, the processes that write it turning it over meanwhile as they would

func Prune

func Prune(dir, pattern string, kept int)

Removes the files of the folder whose names the pattern matches past the kept newest, the newest by when each was written

func Rewrite

func Rewrite(record []byte, rewrite func(text string) string) ([]byte, map[string]string)

The record with its texts rewritten as Rewritten rewrites them, a line as the one it was handed, and the fields at its top that are text, rewritten too, by name. A record that is no JSON object comes back whole through rewrite, with no fields

func Rewritten

func Rewritten(next io.Writer, rewrite func(text string) string) zerolog.LevelWriter

Writer handing each record on to next with every text in it put through rewrite: its message and each value of its fields that is text, those inside lists and groups too. The names of the fields, the level and the time stay as they are, and a record that is no JSON goes through rewrite whole

func SetLevel

func SetLevel(level zerolog.Level)

Has the process write its records from the level up from now on for its files. The terminal shows what Show says whatever this is

func Show

func Show(level zerolog.Level)

Has the terminal show the records from the level up from now on, zerolog.Disabled for none, the process writing them from there when it wrote fewer

func Slog

func Slog() *slog.Logger

Logger for a library that writes its log through slog: its records go through the logger of the process as that is when each is written, at the level slog gave them. It is the default of slog, which the standard log package writes through too

func Trim

func Trim(path string, size int64, keep int) error

Turns over the log at the path that another program writes, such as a child that outlives icebath, once it holds more than size bytes: copied to .1, each older one a number up and the oldest past keep removed, then emptied, so the program goes on writing to the file it holds. What it writes between the copy and the emptying is lost. Nothing for a file that is not there or a zero size

Types

type File

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

A log file several processes write: each record appended in one write of its own, and the file turned over once it would grow past its size: it moves to .1, the one before to .2 and so on, the oldest past the count kept dropped, or it starts again empty when none are kept. The process that turns it over holds the lock beside it. Every other finds the file it wrote to turned over and opens the new one before its next record. A new file is the owner's alone, given the owner of its folder when this process runs as root

func NewFile

func NewFile(path string, size int64, keep int) *File

File of the log at the path, turned over past size bytes with keep older files kept, opened with its first record. Its folder is made when missing, the one above it never

func (*File) Close

func (f *File) Close() error

func (*File) Failed

func (f *File) Failed() (error, time.Time)

Why the file could not be written last and since when its writes fail, nil while records go through

func (*File) Limit

func (f *File) Limit(size int64, keep int)

Turns the file over past size bytes with keep older files kept from its next record on

func (*File) Older

func (f *File) Older() []string

The files of the log turned over, the newest first, as far as they are there

func (*File) Path

func (f *File) Path() string

func (*File) Within

func (f *File) Within(root string) *File

Has the folders between root and the file made as they are needed, root itself never. The file, for chaining

func (*File) Write

func (f *File) Write(p []byte) (int, error)

type LineWriter

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

What a program writes to its standard output or error, written on as whole lines, each put through rewrite: a secret is masked whole rather than in the halves two writes split it into, and the lines of several programs writing one log never mix. A failure to write on is never the program's: the file keeps why it failed

func Lines

func Lines(next io.Writer, rewrite func(line string) string) *LineWriter

Writer of the lines a program writes to next, each through rewrite, which gets a line without its line break and may return several

func (*LineWriter) Close

func (w *LineWriter) Close() error

Writes what is left as a line, and closes next when it closes

func (*LineWriter) Flush

func (w *LineWriter) Flush()

Writes what came after the last line break as a line of its own

func (*LineWriter) Write

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

type Sink

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

A place the records of a log go that can change while loggers write to it, so every logger made over it follows the change

func (*Sink) Held

func (s *Sink) Held() [][]byte

The records written since the process started, each a line of JSON, given once to the logs host, which writes them to the files and shows the terminal what it shows of them. None are kept after

func (*Sink) Mask

func (s *Sink) Mask(rewrite func(text string) string)

Has every record written from now on have its texts rewritten before it goes where it goes, as Rewritten rewrites them

func (*Sink) Route

func (s *Sink) Route(w io.Writer) (back func())

Sends the records to the writer from now on, and gives what sends them back where they went

func (*Sink) Write

func (s *Sink) Write(record []byte) (int, error)

func (*Sink) WriteLevel

func (s *Sink) WriteLevel(level zerolog.Level, record []byte) (int, error)

Jump to

Keyboard shortcuts

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