mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-22 07:00:44 +01:00
logger.Levle: implement flag.Value
This commit is contained in:
parent
01e0519b7b
commit
6f68c98c16
@ -1,6 +1,7 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
@ -23,6 +24,29 @@ func (l *Level) UnmarshalJSON(input []byte) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// implement flag.Value
|
||||
// implement github.com/spf13/pflag.Value
|
||||
func (l *Level) Set(s string) error {
|
||||
newl, err := ParseLevel(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*l = newl
|
||||
return nil
|
||||
}
|
||||
|
||||
// implement github.com/spf13/pflag.Value
|
||||
func (l *Level) Type() string {
|
||||
var buf bytes.Buffer
|
||||
for i, l := range AllLevels {
|
||||
fmt.Fprintf(&buf, "%s", l)
|
||||
if i != len(AllLevels)-1 {
|
||||
fmt.Fprintf(&buf, "|")
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("(%s)", buf.String())
|
||||
}
|
||||
|
||||
const (
|
||||
Debug Level = iota
|
||||
Info
|
||||
|
Loading…
Reference in New Issue
Block a user