Merge pull request #22620 from yongtang/05092016-remove-deprecated-driver-specific-log-tags
Remove deprecated driver specific log tags
This commit is contained in:
commit
7fd9f9964a
|
@ -57,8 +57,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a fluentd logger using the configuration passed in on
|
// New creates a fluentd logger using the configuration passed in on
|
||||||
// the context. Supported context configuration variables are
|
// the context. The supported context configuration variable is
|
||||||
// fluentd-address & fluentd-tag.
|
// fluentd-address.
|
||||||
func New(ctx logger.Context) (logger.Logger, error) {
|
func New(ctx logger.Context) (logger.Logger, error) {
|
||||||
host, port, err := parseAddress(ctx.Config[addressKey])
|
host, port, err := parseAddress(ctx.Config[addressKey])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -154,12 +154,11 @@ func (f *fluentd) Name() string {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateLogOpt looks for fluentd specific log options fluentd-address & fluentd-tag.
|
// ValidateLogOpt looks for fluentd specific log option fluentd-address.
|
||||||
func ValidateLogOpt(cfg map[string]string) error {
|
func ValidateLogOpt(cfg map[string]string) error {
|
||||||
for key := range cfg {
|
for key := range cfg {
|
||||||
switch key {
|
switch key {
|
||||||
case "env":
|
case "env":
|
||||||
case "fluentd-tag":
|
|
||||||
case "labels":
|
case "labels":
|
||||||
case "tag":
|
case "tag":
|
||||||
case addressKey:
|
case addressKey:
|
||||||
|
|
|
@ -40,8 +40,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a gelf logger using the configuration passed in on the
|
// New creates a gelf logger using the configuration passed in on the
|
||||||
// context. Supported context configuration variables are
|
// context. The supported context configuration variable is gelf-address.
|
||||||
// gelf-address, & gelf-tag.
|
|
||||||
func New(ctx logger.Context) (logger.Logger, error) {
|
func New(ctx logger.Context) (logger.Logger, error) {
|
||||||
// parse gelf address
|
// parse gelf address
|
||||||
address, err := parseAddress(ctx.Config["gelf-address"])
|
address, err := parseAddress(ctx.Config["gelf-address"])
|
||||||
|
@ -153,13 +152,11 @@ func (s *gelfLogger) Name() string {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateLogOpt looks for gelf specific log options gelf-address, &
|
// ValidateLogOpt looks for gelf specific log option gelf-address.
|
||||||
// gelf-tag.
|
|
||||||
func ValidateLogOpt(cfg map[string]string) error {
|
func ValidateLogOpt(cfg map[string]string) error {
|
||||||
for key, val := range cfg {
|
for key, val := range cfg {
|
||||||
switch key {
|
switch key {
|
||||||
case "gelf-address":
|
case "gelf-address":
|
||||||
case "gelf-tag":
|
|
||||||
case "tag":
|
case "tag":
|
||||||
case "labels":
|
case "labels":
|
||||||
case "env":
|
case "env":
|
||||||
|
|
|
@ -2,9 +2,7 @@ package loggerutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/docker/docker/daemon/logger"
|
"github.com/docker/docker/daemon/logger"
|
||||||
"github.com/docker/docker/utils/templates"
|
"github.com/docker/docker/utils/templates"
|
||||||
)
|
)
|
||||||
|
@ -12,7 +10,10 @@ import (
|
||||||
// ParseLogTag generates a context aware tag for consistency across different
|
// ParseLogTag generates a context aware tag for consistency across different
|
||||||
// log drivers based on the context of the running container.
|
// log drivers based on the context of the running container.
|
||||||
func ParseLogTag(ctx logger.Context, defaultTemplate string) (string, error) {
|
func ParseLogTag(ctx logger.Context, defaultTemplate string) (string, error) {
|
||||||
tagTemplate := lookupTagTemplate(ctx, defaultTemplate)
|
tagTemplate := ctx.Config["tag"]
|
||||||
|
if tagTemplate == "" {
|
||||||
|
tagTemplate = defaultTemplate
|
||||||
|
}
|
||||||
|
|
||||||
tmpl, err := templates.NewParse("log-tag", tagTemplate)
|
tmpl, err := templates.NewParse("log-tag", tagTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -25,22 +26,3 @@ func ParseLogTag(ctx logger.Context, defaultTemplate string) (string, error) {
|
||||||
|
|
||||||
return buf.String(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupTagTemplate(ctx logger.Context, defaultTemplate string) string {
|
|
||||||
tagTemplate := ctx.Config["tag"]
|
|
||||||
|
|
||||||
deprecatedConfigs := []string{"syslog-tag", "gelf-tag", "fluentd-tag"}
|
|
||||||
for i := 0; tagTemplate == "" && i < len(deprecatedConfigs); i++ {
|
|
||||||
cfg := deprecatedConfigs[i]
|
|
||||||
if ctx.Config[cfg] != "" {
|
|
||||||
tagTemplate = ctx.Config[cfg]
|
|
||||||
logrus.Warn(fmt.Sprintf("Using log tag from deprecated log-opt '%s'. Please use: --log-opt tag=\"%s\"", cfg, tagTemplate))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tagTemplate == "" {
|
|
||||||
tagTemplate = defaultTemplate
|
|
||||||
}
|
|
||||||
|
|
||||||
return tagTemplate
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,24 +18,6 @@ func TestParseLogTag(t *testing.T) {
|
||||||
assertTag(t, e, tag, "test-image/test-container/container-ab")
|
assertTag(t, e, tag, "test-image/test-container/container-ab")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseLogTagSyslogTag(t *testing.T) {
|
|
||||||
ctx := buildContext(map[string]string{"syslog-tag": "{{.ImageName}}/{{.Name}}/{{.ID}}"})
|
|
||||||
tag, e := ParseLogTag(ctx, "{{.ID}}")
|
|
||||||
assertTag(t, e, tag, "test-image/test-container/container-ab")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseLogTagGelfTag(t *testing.T) {
|
|
||||||
ctx := buildContext(map[string]string{"gelf-tag": "{{.ImageName}}/{{.Name}}/{{.ID}}"})
|
|
||||||
tag, e := ParseLogTag(ctx, "{{.ID}}")
|
|
||||||
assertTag(t, e, tag, "test-image/test-container/container-ab")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseLogTagFluentdTag(t *testing.T) {
|
|
||||||
ctx := buildContext(map[string]string{"fluentd-tag": "{{.ImageName}}/{{.Name}}/{{.ID}}"})
|
|
||||||
tag, e := ParseLogTag(ctx, "{{.ID}}")
|
|
||||||
assertTag(t, e, tag, "test-image/test-container/container-ab")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|
||||||
func buildContext(cfg map[string]string) logger.Context {
|
func buildContext(cfg map[string]string) logger.Context {
|
||||||
|
|
|
@ -89,7 +89,7 @@ func rfc5424microformatterWithAppNameAsTag(p syslog.Priority, hostname, tag, con
|
||||||
|
|
||||||
// New creates a syslog logger using the configuration passed in on
|
// New creates a syslog logger using the configuration passed in on
|
||||||
// the context. Supported context configuration variables are
|
// the context. Supported context configuration variables are
|
||||||
// syslog-address, syslog-facility, syslog-format, syslog-tag.
|
// syslog-address, syslog-facility, syslog-format.
|
||||||
func New(ctx logger.Context) (logger.Logger, error) {
|
func New(ctx logger.Context) (logger.Logger, error) {
|
||||||
tag, err := loggerutils.ParseLogTag(ctx, "{{.ID}}")
|
tag, err := loggerutils.ParseLogTag(ctx, "{{.ID}}")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -184,7 +184,7 @@ func parseAddress(address string) (string, string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateLogOpt looks for syslog specific log options
|
// ValidateLogOpt looks for syslog specific log options
|
||||||
// syslog-address, syslog-facility, & syslog-tag.
|
// syslog-address, syslog-facility.
|
||||||
func ValidateLogOpt(cfg map[string]string) error {
|
func ValidateLogOpt(cfg map[string]string) error {
|
||||||
for key := range cfg {
|
for key := range cfg {
|
||||||
switch key {
|
switch key {
|
||||||
|
@ -192,7 +192,6 @@ func ValidateLogOpt(cfg map[string]string) error {
|
||||||
case "labels":
|
case "labels":
|
||||||
case "syslog-address":
|
case "syslog-address":
|
||||||
case "syslog-facility":
|
case "syslog-facility":
|
||||||
case "syslog-tag":
|
|
||||||
case "syslog-tls-ca-cert":
|
case "syslog-tls-ca-cert":
|
||||||
case "syslog-tls-cert":
|
case "syslog-tls-cert":
|
||||||
case "syslog-tls-key":
|
case "syslog-tls-key":
|
||||||
|
|
|
@ -64,8 +64,3 @@ Apr 1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: + exec app
|
||||||
Apr 1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: 2016-04-01 15:22:17.075416751 +0000 UTC stderr msg: 1
|
Apr 1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: 2016-04-01 15:22:17.075416751 +0000 UTC stderr msg: 1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
>**Note**:The driver specific log options `syslog-tag`, `fluentd-tag` and
|
|
||||||
>`gelf-tag` still work for backwards compatibility. However, going forward you
|
|
||||||
>should standardize on using the generic `tag` log option instead.
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ variants:
|
||||||
### Driver Specific Log Tags
|
### Driver Specific Log Tags
|
||||||
**Deprecated In Release: v1.9**
|
**Deprecated In Release: v1.9**
|
||||||
|
|
||||||
**Target For Removal In Release: v1.11**
|
**Removed In Release: v1.12**
|
||||||
|
|
||||||
Log tags are now generated in a standard way across different logging drivers.
|
Log tags are now generated in a standard way across different logging drivers.
|
||||||
Because of which, the driver specific log tag options `syslog-tag`, `gelf-tag` and
|
Because of which, the driver specific log tag options `syslog-tag`, `gelf-tag` and
|
||||||
|
|
Loading…
Reference in New Issue