cage

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cage copies all output to stdout, stderr and log output in a logfile.

Usage: cage.Name = cage.DefaultLogfileName cage.Enable() defer cage.Disable() do stuff... for capturing output in a string consider "import capturer "github.com/kami-zh/go-capturer"

TODO: debug code:

Problem:
cage.Enable() re-direkted os.Stderr und dupliziert so Ausgaben an os.Sterr in trice.log
hCmd.Output() usw. geben os.Stderr zurück. Das ist auch wirklich die re-directed Adresse.
Der Paketest von cage funktioniert, auch TestScHelp() geht fehlerfrei durch.
Wenn aber über die Kommandozeile "trice h" erfolgt, landen Ausgaben an os.Stderr NICHT in trice.log obwohl os.Stderr re-directed ist.
	log.SetFlags(0)
	fmt.Println("0: os.Stderr     addr:", os.Stderr) // ok not in trice.log
	cage.Enable()
	defer cage.Disable()
	fmt.Println("1: os.Stderr     addr:", os.Stderr)     // ok in trice.log (os.Stdout)
	fmt.Println("2: hCmd.Output() addr:", hCmd.Output()) // ok in trice.log (os.Stdout)

	fmt.Fprintln(os.Stderr, "3:      OS.STDERR")       // NOT in trice.log
	fmt.Fprintln(hCmd.Output(), "4:    hCmd.Output()") // NOT in trice.log
	log.Println("5: TryIt")                            // ok in trice.log (log out)
	fmt.Println("6: TryIt2")                           // ok in trice.log (os.Stdout)
	fmt.Fprintln(os.Stdout, "7:      OS.STDOUT")       // ok in trice.log (os.Stdout)

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLogfileName is the pattern for default logfile name. The timestamp is replaced with the actual time.
	DefaultLogfileName = "2006-01-02_1504-05_cage.log"

	// Name is the filename of the logfile. "off" inhibits logfile writing.
	Name = "off"
)

Functions

func Disable

func Disable()

Disable ends take notes mode, means parallel writing into a file. It takes no effect when pContainer is nil, what is the case when Enable was started with "off" or "none" as 'Name'.

func Enable

func Enable()

Enable starts take notes mode, means parallel writing into a file. Name has to be assigned to a value other than "off" or "none" for taking effect.

func Stop

func Stop(c *Container)

Stop does return to normal state.

Types

type Container

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

Container keeps re-direction informantion for restoring

func Start

func Start(fn string) *Container

Start does append all output parallel into a logfile with name fn

Jump to

Keyboard shortcuts

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