log: support --log-opt tag=

support a custom tag to add to each log for the container.

It is currently supported only by the journald backend.

Closes: https://github.com/containers/libpod/issues/3653

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2020-01-07 13:41:56 +01:00
parent f3fc10feb4
commit 71341a1948
9 changed files with 133 additions and 19 deletions

View File

@ -132,16 +132,23 @@ func validateIOpsDevice(val string) (*throttleDevice, error) { //nolint
}, nil
}
func getLoggingPath(opts []string) string {
// getLoggingOpts splits the path= and tag= options provided to --log-opt.
func getLoggingOpts(opts []string) (string, string) {
var path, tag string
for _, opt := range opts {
arr := strings.SplitN(opt, "=", 2)
if len(arr) == 2 {
if strings.TrimSpace(arr[0]) == "path" {
return strings.TrimSpace(arr[1])
path = strings.TrimSpace(arr[1])
} else if strings.TrimSpace(arr[0]) == "tag" {
tag = strings.TrimSpace(arr[1])
}
}
if path != "" && tag != "" {
break
}
}
return ""
return path, tag
}
// ParseDevice parses device mapping string to a src, dest & permissions string