-
Notifications
You must be signed in to change notification settings - Fork 667
Use log timestamps from docker logs. #401
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
d0e8c0f
c49aff9
0caaeee
f00a3c2
41f0437
18772e0
a783720
5e7a964
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ func getopt(name, dfault string) string { | |
| return value | ||
| } | ||
|
|
||
| func originalTimestamps() bool { | ||
| return getopt("ORIGINAL_TIMESTAMPS", "false") == "true" | ||
| } | ||
|
|
||
| func debug(v ...interface{}) { | ||
| if os.Getenv("DEBUG") != "" { | ||
| log.Println(v...) | ||
|
|
@@ -244,6 +248,7 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool, inactivityTim | |
| Since: sinceTime.Unix(), | ||
| InactivityTimeout: inactivityTimeout, | ||
| RawTerminal: rawTerminal, | ||
| Timestamps: originalTimestamps(), | ||
| }) | ||
| if err != nil { | ||
| debug("pump.pumpLogs():", id, "stopped with error:", err) | ||
|
|
@@ -370,10 +375,11 @@ func newContainerPump(container *docker.Container, stdout, stderr io.Reader) *co | |
| } | ||
| return | ||
| } | ||
| logMessage, logTime := parseLogLine(line, originalTimestamps()) | ||
| cp.send(&Message{ | ||
| Data: strings.TrimSuffix(line, "\n"), | ||
| Data: logMessage, | ||
| Container: container, | ||
| Time: time.Now(), | ||
| Time: logTime, | ||
| Source: source, | ||
| }) | ||
| } | ||
|
|
@@ -405,3 +411,22 @@ func (cp *containerPump) remove(logstream chan *Message) { | |
| defer cp.Unlock() | ||
| delete(cp.logstreams, logstream) | ||
| } | ||
|
|
||
| func parseLogLine(line string, originalTimestamps bool) (string, time.Time) { | ||
| line = strings.TrimSuffix(line, "\n") | ||
|
|
||
| if ! originalTimestamps { | ||
| return line, time.Now() | ||
| } | ||
|
|
||
| logEntry := strings.SplitN(line, " ", 2) | ||
| logTime, err := time.Parse(time.RFC3339Nano, logEntry[0]) | ||
| if err != nil { | ||
| return line, time.Now() | ||
| } | ||
|
|
||
| if len(logEntry) == 2 { | ||
| return logEntry[1], logTime | ||
| } | ||
| return "", logTime | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we want to return an empty log line? Shouldn't this also be:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.