Help us shape the future of Go! Take the 2026 Go Developer Survey

zlog

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logging configures the process-wide zerolog logger.

Logs go to stderr so they never contaminate a remote command's stdout, which matters for `ohmyssh exec host -- cmd` being used in a pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detach

func Detach(path string) func()

Detach points the global logger at a file, for as long as something other than this process owns the terminal, and returns the function that gives stderr back.

A full-screen view draws with the alt screen and reads the keyboard in raw mode, so a line written to the terminal lands in the middle of a frame: the renderer repaints only the lines that changed and moves the cursor by the count it believes it drew, so every write leaves a row of the frame above it on screen. One line of corruption per line of log, which for a view that dials on every open is a new line every time the user opens it. Logs go to a file while the view is up instead, which is also where a report of what it did is worth reading afterwards.

The level and the console-or-JSON choice are the ones Setup installed. The time stamp gains the date, because a file is read on a later day than the one it was written on and an hour and minute would not say which. A path that cannot be opened silences the logs rather than falling back to stderr — the terminal is the one place they cannot go — and the returned function restores stderr either way.

func L

func L() *zerolog.Logger

L returns the configured logger.

func Output

func Output() io.Writer

Output is where the logs are going now: stderr, or the file Detach opened for as long as a view owns the terminal.

Text that is not a log line — a server's login banner, the stderr of a ProxyCommand — belongs here rather than straight to os.Stderr, because the terminal is the one place it cannot go while a view is drawing on it: the renderer moves the cursor by the lines it believes it drew, so anything printed beside the frame leaves it shifted by a row. Nothing detached hands the writer the options named, which is stderr itself unless a caller chose another, so a command line's output does not change.

func Setup

func Setup(opts Options) zerolog.Logger

Setup builds the global logger and returns it. An unparsable level is reported by falling back to info rather than aborting, so a typo in --log-level never prevents a connection attempt.

Types

type Options

type Options struct {
	Level  string // trace, debug, info, warn, error, fatal, panic, disabled
	Pretty bool   // human-readable console output instead of JSON
	Stderr io.Writer
	// TimeFormat is how a console line stamps its time, in Go's layout syntax. It
	// is empty by default, which is time.TimeOnly: a terminal is watched as it
	// happens, so the hour and minute are what a line there needs. A file is read
	// the next day as well, so Detach asks for the date as well as the time. It
	// says nothing about the JSON format, which stamps RFC 3339 either way.
	TimeFormat string
}

Options controls logger construction.

Jump to

Keyboard shortcuts

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