logger

package module
v0.0.0-...-7dfebbe Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2017 License: BSD-2-Clause Imports: 4 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

paraphernalia/logger

License Go Doc Build Status

License

2-Clause BSD

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var NoMatchingDef error = fmt.Errorf("No Matching Definition Found")

Functions

This section is empty.

Types

type Definition

type Definition interface {
	LoggerFound(buffer []byte) (Logger, bool)
	DefaultLogger() Logger
	String() string
}
var (
	Stderr Definition = register(new(d_stderr))
	Stdout Definition = register(new(d_stdout))
)
var NoLog Definition = register(new(d_null))

func GenericWriter

func GenericWriter(name string, w io.Writer) Definition

type Factory

type Factory struct {
	CustomFlagHelper func([]string) string
	// contains filtered or unexported fields
}

func (*Factory) FlagHelper

func (l *Factory) FlagHelper() string

func (*Factory) Get

func (l *Factory) Get() interface{}

func (*Factory) LoggerFound

func (l *Factory) LoggerFound() Logger

func (*Factory) MarshalText

func (p *Factory) MarshalText() ([]byte, error)

func (*Factory) Register

func (l *Factory) Register(defs ...Definition)

func (*Factory) Set

func (l *Factory) Set(data string) error
Example
fs := flag.NewFlagSet("", flag.ExitOnError)

fact := &Factory{
	CustomFlagHelper: func(d []string) string {
		return "choose a flag in : " + strings.Join(d, ", ")
	},
}

fact.Register(Stdout, NoLog)
fact.SetDefault(NoLog)

fs.SetOutput(os.Stdout)
fs.Var(fact, "output", fact.FlagHelper())

fs.PrintDefaults()
fs.Parse([]string{"-output=stdout"})

log := fact.LoggerFound()
log.Printf("hello %s\n", log)
Output:
-output value
    	choose a flag in : stdout, null (default null)
hello stdout

func (*Factory) SetDefault

func (l *Factory) SetDefault(def Definition)

func (*Factory) String

func (l *Factory) String() string

func (*Factory) UnmarshalText

func (p *Factory) UnmarshalText(text []byte) error
Example
var t struct {
	Log *Factory `json:"output"`
}

data := []byte(`{"output":"stdout"}`)

if err := json.Unmarshal(data, &t); err != nil {
	log.Fatal(err)
}

if t.Log == nil {
	log.Fatal("no output parsed")
}

output := t.Log.LoggerFound()
if output == nil {
	log.Fatal("no output found")
}

output.Printf("hello %s\n", output)
Output:
hello stdout

type Logger

type Logger interface {
	io.Writer
	Print(v ...interface{})
	Println(v ...interface{})
	Printf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalln(v ...interface{})
	Fatalf(format string, v ...interface{})
	Logger(prefix string, flag int) *log.Logger
	String() string
}

Jump to

Keyboard shortcuts

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