UnmarshalText unmarshals text to a level. Like MarshalText, UnmarshalText expects the text representation of a Level to drop the -Level suffix (see example). In particular, this makes it easy to configure logging levels using YAML, TOML, or JSON files.
(text []byte)
| 168 | // In particular, this makes it easy to configure logging levels using YAML, |
| 169 | // TOML, or JSON files. |
| 170 | func (l *Level) UnmarshalText(text []byte) error { |
| 171 | if l == nil { |
| 172 | return errUnmarshalNilLevel |
| 173 | } |
| 174 | if !l.unmarshalText(text) && !l.unmarshalText(bytes.ToLower(text)) { |
| 175 | return fmt.Errorf("unrecognized level: %q", text) |
| 176 | } |
| 177 | return nil |
| 178 | } |
| 179 | |
| 180 | func (l *Level) unmarshalText(text []byte) bool { |
| 181 | switch string(text) { |