Documentation
¶
Index ¶
- Variables
- type Definition
- type Factory
- func (l *Factory) FlagHelper() string
- func (l *Factory) Get() interface{}
- func (l *Factory) LoggerFound() Logger
- func (p *Factory) MarshalText() ([]byte, error)
- func (l *Factory) Register(defs ...Definition)
- func (l *Factory) Set(data string) error
- func (l *Factory) SetDefault(def Definition)
- func (l *Factory) String() string
- func (p *Factory) UnmarshalText(text []byte) error
- type Logger
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 (*Factory) LoggerFound ¶
func (*Factory) MarshalText ¶
func (*Factory) Register ¶
func (l *Factory) Register(defs ...Definition)
func (*Factory) Set ¶
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) UnmarshalText ¶
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
Click to show internal directories.
Click to hide internal directories.