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
- Variables
- func Adopt(path string) error
- func Capture(path string, keep int) (*os.File, error)
- func Console() zerolog.LevelWriter
- func Crashes(path string, size int64, keep int) error
- func Foreign(path string) bool
- func Note(path string, text []byte) error
- func Older(path string, keep int) []string
- func Open(path string) (*os.File, error)
- func Prune(dir, pattern string, kept int)
- func Rewrite(record []byte, rewrite func(text string) string) ([]byte, map[string]string)
- func Rewritten(next io.Writer, rewrite func(text string) string) zerolog.LevelWriter
- func SetLevel(level zerolog.Level)
- func Show(level zerolog.Level)
- func Slog() *slog.Logger
- func Trim(path string, size int64, keep int) error
- type File
- type LineWriter
- type Sink
Constants ¶
const Told = "told"
Field a record carries as true when its words were said to the person 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 person reads the words once
Variables ¶
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 ¶
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 ¶
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 person 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 person was told there already
func Crashes ¶
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 ¶
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 ¶
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 ¶
The files the log at the path turned over, the newest first, as far as they are there among the count kept
func Open ¶
Opens the log file at the path to read, the processes that write it turning it over meanwhile as they would
func Prune ¶
Removes the files of the folder whose names the pattern matches past the kept newest, the newest by when each was written
func Rewrite ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Failed ¶
Why the file could not be written last and since when its writes fail, nil while records go through
func (*File) Limit ¶
Turns the file over past size bytes with keep older files kept from its next record on
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
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 ¶
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 ¶
Has every record written from now on have its texts rewritten before it goes where it goes, as Rewritten rewrites them