mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-22 15:11:16 +01:00
logger.Levle: implement flag.Value
This commit is contained in:
parent
01e0519b7b
commit
6f68c98c16
@ -1,6 +1,7 @@
|
|||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -23,6 +24,29 @@ func (l *Level) UnmarshalJSON(input []byte) (err error) {
|
|||||||
return err
|
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 (
|
const (
|
||||||
Debug Level = iota
|
Debug Level = iota
|
||||||
Info
|
Info
|
||||||
|
Loading…
Reference in New Issue
Block a user