mirror of
https://github.com/gravitational/teleport
synced 2024-10-22 02:03:24 +00:00
Format logs and remove timestamp from default log format (#5979)
* make log formatting customizable * import trace * add documentation for log formatting * add testing and validate input * PR feedback * nit * PR feedback * remove format values dupe * remove message * remove timestamp from default log formatting
This commit is contained in:
parent
cd399e704c
commit
e174428adb
|
@ -56,11 +56,11 @@ teleport:
|
|||
|
||||
# Logging configuration. Possible output values to disk via '/var/lib/teleport/teleport.log',
|
||||
# 'stdout', 'stderr' and 'syslog'. Possible severity values are INFO, WARN
|
||||
# and ERROR (default). Possible format values include: timestamp, component, message, caller, and level.
|
||||
# and ERROR (default). Possible format values include: timestamp, component, caller, and level.
|
||||
log:
|
||||
output: /var/lib/teleport/teleport.log
|
||||
severity: ERROR
|
||||
format: [level, timestamp, component, message]
|
||||
format: [level, timestamp, component, caller]
|
||||
|
||||
# Configuration for the storage back-end used for the cluster state and the
|
||||
# audit log. Several back-end types are supported. See the "High Availability"
|
||||
|
|
|
@ -459,7 +459,7 @@ type Log struct {
|
|||
Output string `yaml:"output,omitempty"`
|
||||
// Severity defines how verbose the log will be. Possible valus are "error", "info", "warn"
|
||||
Severity string `yaml:"severity,omitempty"`
|
||||
// Format lists the output fields from KnownFormatFields. Example format: [timestamp, component, message]
|
||||
// Format lists the output fields from KnownFormatFields. Example format: [timestamp, component, caller]
|
||||
Format []string `yaml:"format,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gravitational/teleport/api/utils"
|
||||
"github.com/gravitational/trace"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -75,7 +76,6 @@ func (tf *textFormatter) CheckAndSetDefaults() error {
|
|||
|
||||
// set log formatting
|
||||
if tf.LogFormat == nil {
|
||||
tf.timestampEnabled = true
|
||||
tf.callerEnabled = true
|
||||
tf.LogFormat = KnownFormatFields.names()
|
||||
return nil
|
||||
|
@ -85,11 +85,12 @@ func (tf *textFormatter) CheckAndSetDefaults() error {
|
|||
if err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
if contains(res, timestampField) {
|
||||
|
||||
if utils.SliceContainsStr(res, timestampField) {
|
||||
tf.timestampEnabled = true
|
||||
}
|
||||
|
||||
if contains(res, callerField) {
|
||||
if utils.SliceContainsStr(res, callerField) {
|
||||
tf.callerEnabled = true
|
||||
}
|
||||
|
||||
|
@ -362,13 +363,3 @@ func parseInputFormat(formatInput []string) (result []string, err error) {
|
|||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func contains(s []string, str string) bool {
|
||||
for _, v := range s {
|
||||
if v == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue