Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v0.0.6
type Option func(*options)
Option configures RedirectStdToFiles / RedirectStdToFilesIn.
func TapStdout ¶ added in v0.0.6
TapStdout adds a live copy of every line written to stdout. An app that owns the terminal itself, like a tui, can use it to show the output of the standard logger and of libraries printing to stdout instead of only finding it in the file after the run.
The tap is called from a reader goroutine, with the line stripped of its newline, and must not print to stdout itself, which would feed straight back into it. Restore waits until everything written before it has been passed on.
type RestoreSTD ¶
type RestoreSTD struct {
// contains filtered or unexported fields
}
func RedirectStdToFiles ¶
func RedirectStdToFiles(opts ...Option) (*RestoreSTD, error)
RedirectStdToFiles replaces stdout and stderr with file writers in the working directory. The returned struct has functions to revert replacement of stdout and err with fs files.
func RedirectStdToFilesIn ¶ added in v0.0.2
func RedirectStdToFilesIn(dir string, opts ...Option) (*RestoreSTD, error)
RedirectStdToFilesIn is RedirectStdToFiles writing into dir, which is created if it does not exist. An app that already has a place for its scratch files can keep the logs there instead of dropping them wherever it was started.
func (*RestoreSTD) AddCallback ¶
func (r *RestoreSTD) AddCallback(f func())
func (*RestoreSTD) Restore ¶
func (r *RestoreSTD) Restore()
Restore puts the real stdout and stderr back. The order matters, the pipes are closed only once nothing can write to them any more, and the files only once the readers have drained what was still in flight.
func (*RestoreSTD) Run ¶
func (r *RestoreSTD) Run(f func())