64 lines
1.0 KiB
Go
64 lines
1.0 KiB
Go
package log
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
type outFormat string
|
|
|
|
var (
|
|
errUnmarshalNilFormat = errors.New("can't unmarshal a nil *outFormat")
|
|
)
|
|
|
|
const (
|
|
Json outFormat = "json"
|
|
console outFormat = "console"
|
|
)
|
|
|
|
func (f *outFormat) parseFormat(text string) (outFormat, error) {
|
|
var format outFormat
|
|
err := format.UnmarshalText([]byte(text))
|
|
return format, err
|
|
}
|
|
|
|
func (f *outFormat) UnmarshalText(text []byte) error {
|
|
if f == nil {
|
|
return errUnmarshalNilFormat
|
|
}
|
|
|
|
if !f.unmarshalText(text) && !f.unmarshalText(bytes.ToLower(text)) {
|
|
return fmt.Errorf("unrecognized outFormat: %q", text)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (f *outFormat) unmarshalText(text []byte) bool {
|
|
switch string(text) {
|
|
case "json", "JSON":
|
|
*f = Json
|
|
case "console", "CONSOLE", "":
|
|
*f = console
|
|
default:
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func (c *syncConf) setDefaultSyncConf() {
|
|
if c.MaxAges <= 0 {
|
|
c.MaxAges = defaultMaxAges
|
|
}
|
|
|
|
if c.MaxBackUps <= 0 {
|
|
c.MaxBackUps = defaultMaxBAckUps
|
|
}
|
|
|
|
if c.MaxAges <= 0 {
|
|
c.MaxSize = defaultMaxSize
|
|
}
|
|
}
|