Files
faas-cli/flags/log_format.go
Lucas Roesler 893972afff Add flags to control the log output format
**What**
- Add new flags to toggle the name, instance, and timestamp fields.
Additionally, the new `time-format` also allows controlling the actual
timestamp format.
- Also provide the log format flag to allow printing the output as JSON,
key-values, or the plain format.  This should make it easy to integrate
with other tools, like JQ etc.

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
2019-08-19 15:00:32 +01:00

38 lines
716 B
Go

package flags
import (
"fmt"
"strings"
)
// LogFormat determines the output format of the log stream
type LogFormat string
const PlainLogFormat LogFormat = "plain"
const KeyValueLogFormat LogFormat = "keyvalue"
const JSONLogFormat LogFormat = "json"
// Type implements pflag.Value
func (l *LogFormat) Type() string {
return "logformat"
}
// String implements Stringer
func (l *LogFormat) String() string {
if l == nil {
return ""
}
return string(*l)
}
// Set implements pflag.Value
func (l *LogFormat) Set(value string) error {
switch strings.ToLower(value) {
case "plain", "keyvalue", "json":
*l = LogFormat(value)
default:
return fmt.Errorf("unknown log format: '%s'", value)
}
return nil
}