io

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2015 License: MIT, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMultiWriter

func NewMultiWriter() io.Writer

NewMultiWriter returns an initialized MultiWriter.

Types

type Colorizer

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

Colorizer is a Colorizing logger middleman.

This can be used to colorize logs as they pass through to another writer. The colorization uses the UNIX-style shell color coding.

TODO: This is a very basic implementation, and could use some TLC.

Example Usage:

 import (
		"github.com/Masterminds/cookoo"
		"github.com/Masterminds/cookoo/io"
		// And other stuff
		cio "io"
	)
	func main() {
		reg, router, cxt := cookoo.Cookoo()
		clogger := io.NewColorizer(cio.Stdout)
		cxt.AddLogger("stdout", clogger)
		// etc.
	}

Given the above, log messages will be colorized before written to `io.Stdout`.

func NewColorizer

func NewColorizer(writer cio.Writer) *Colorizer

NewColorizer creates a new colorizer that wraps a given io.Writer.

func (*Colorizer) Write

func (r *Colorizer) Write(data []byte) (int, error)

Write colorizes a message and then passes it to the underlying writer.

type MultiWriter

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

MultiWriter enables you to have a writer that passes on the writing to one of more Writers where the write is duplicated to each Writer. MultiWriter is similar to the multiWriter that is part of Go. The difference is this MultiWriter allows you to manager the Writers attached to it via CRUD operations. To do this you will need to mock the type. For example, mw := NewMultiWriter() mw.(*MultiWriter).AddWriter("foo", foo)

func (*MultiWriter) AddWriter

func (t *MultiWriter) AddWriter(name string, writer io.Writer)

AddWriter adds an io.Writer with an associated name.

func (*MultiWriter) Init

func (t *MultiWriter) Init() *MultiWriter

Init initializes the MultiWriter.

func (*MultiWriter) RemoveWriter

func (t *MultiWriter) RemoveWriter(name string)

RemoveWriter removes an io.Writer given a name.

func (*MultiWriter) Write

func (t *MultiWriter) Write(p []byte) (n int, err error)

Write sends the bytes to each of the attached writers to be written.

func (*MultiWriter) Writer

func (t *MultiWriter) Writer(name string) (io.Writer, bool)

Writer retrieves a given io.Writer given its name.

func (*MultiWriter) Writers

func (t *MultiWriter) Writers() map[string]io.Writer

Writers retrieves a map of all io.Writers keyed by name.

Jump to

Keyboard shortcuts

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