-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format Logs and add timestamp to logging output option #5898
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot seem to find a way to delete a misplaced PR comment - I did not mean to approve it, there are still open questions.
lib/config/configuration.go
Outdated
for _, match := range tf.InputFormat { | ||
switch match { | ||
case "level": | ||
// level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
LGTM once existing comments are resolved. |
lib/config/fileconf.go
Outdated
@@ -459,6 +459,8 @@ 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 defines the format in which each log line will be outputted. Example format: [timestamp, component, message] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Format defines the format in which each log line will be outputted. Example format: [timestamp, component, message] | |
// Format lists the mandatory output fields from TextFormatterFields. Example format: [timestamp, component, message] |
hence I would store all known fields in a variable (TextFormatterFields
) that can be referred to.
lib/config/formatter.go
Outdated
} | ||
|
||
// DefaultLoggerFormat is the default format in which to display logs (i.e. log.format in teleport.yaml is empty) | ||
var DefaultLoggerFormat = []string{"level", "component", "message", "caller"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move known formatter field literals into corresponding consts since they're used on multiple occasions.
lib/config/formatter.go
Outdated
// Defaults to filePathAndLine() if unspecified | ||
FormatCaller func() (caller string) | ||
// InitFormat is the initial format of log configuration | ||
InitFormat []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need both InitFormat and InputFormat - looks like they're the same most of the time and InitFormat is only used for validation.
lib/config/configuration_test.go
Outdated
@@ -1363,3 +1363,37 @@ func TestDatabaseFlags(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestCheckAndSetDefaults(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the test method does not hint that it has anything to do with the text formatter type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bot.
if err != nil { | ||
return trace.Wrap(err) | ||
} | ||
if contains(res, timestampField) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for late reply: contains
is a dupe for api.types.SliceContainsStr
@@ -56,10 +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). | |||
# and ERROR (default). Possible format values include: timestamp, component, message, caller, and level. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message
@@ -459,6 +459,8 @@ 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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message
Purpose
Format logs with according to teleport config specification.
Implementation
Created a new formatter based off of logrus's text formatter, this new formatter writes to the log line in the order that the user specifies in the file.
Example log config in teleport config file:
Resolves #2676