-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This handler filters out the docker-compose prefix, and then passes on the rest of the line to another handler.
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package humanlog | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
// dcLogsPrefixRe parses out a prefix like 'web_1 | ' from docker-compose | ||
var dcLogsPrefixRe = regexp.MustCompile("^(?:\x1b\\[\\d+m)?([a-zA-Z0-9._-]+)\\s+\\|(?:\x1b\\[0m)? (.*)$") | ||
|
||
type handler interface { | ||
TryHandle([]byte) bool | ||
setField(key, val []byte) | ||
} | ||
|
||
func tryDockerComposePrefix(d []byte, nextHandler handler) bool { | ||
if matches := dcLogsPrefixRe.FindSubmatch(d); matches != nil { | ||
if nextHandler.TryHandle(matches[2]) { | ||
nextHandler.setField([]byte(`service`), matches[1]) | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters