-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
35 lines (29 loc) · 906 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package log
import (
"fmt"
"io"
"testing"
)
// Config is the configuration for the logger.
type Config struct {
// Level sets the minimum log level for the logger.
Level Level `json:"level"`
// Destination is the place the logger writes to.
Destination Destination `json:"destination"`
// T is the Go test for logging purposes.
T *testing.T `json:"-" yaml:"-"`
// Stdout is the standard output used by the DestinationStdout destination. If not set, os.Stdout is used.
Stdout io.Writer `json:"-" yaml:"-"`
}
func (c Config) Validate() error {
if err := c.Level.Validate(); err != nil {
return fmt.Errorf("invalid level value (%w)", err)
}
if err := c.Destination.Validate(); err != nil {
return fmt.Errorf("invalid destination value (%w)", err)
}
if c.Destination == DestinationTest && c.T == nil {
return fmt.Errorf("no T value supplied with destination=test")
}
return nil
}