Skip to content

Commit fc4ee1b

Browse files
authored
Merge pull request #3 from cabify/alvaro.polo/decode-loglevel
Make `Level` type implement `envconfig.Decoder`
2 parents 7f75ecf + aec62f0 commit fc4ee1b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
### Security
2424
- Nothing
2525

26+
## [1.3.0] - 2019-03-18
27+
### Added
28+
- `Level` now implements the `envconfig.Decoder` interface so it can be used in config types
29+
30+
2631
## [1.2.0] - 2019-02-27
2732
### Added
2833
- `ConfigureDefaultLogger` boilerplate for logger configuration

log.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
// Package log is an alternative to log package in standard library.
22
package log
33

4-
import "os"
4+
import (
5+
"fmt"
6+
"os"
7+
)
58

69
type Level int
710

11+
// Decode fills this level from the given input string.
12+
// This makes `Level` implement the `Decoder` interface of `envconfig` library,
13+
// so it can be used in config types seamlessly.
14+
func (l *Level) Decode(val string) error {
15+
if logLevel, ok := logLevelMap[val]; ok {
16+
*l = logLevel
17+
return nil
18+
} else {
19+
return fmt.Errorf("Unknown log level configured: %s", val)
20+
}
21+
}
22+
823
// Logging levels.
924
const (
1025
CRITICAL Level = iota

0 commit comments

Comments
 (0)