// New creates a new etwLogs logger for the given container and registers the EWT provider. func New(info logger.Info) (logger.Logger, error) { if err := registerETWProvider(); err != nil { return nil, err } logrus.Debugf("logging driver etwLogs configured for container: %s.", info.ContainerID) return &etwLogs{ containerName: info.Name(), imageName: info.ContainerImageName, containerID: info.ContainerID, imageID: info.ContainerImageID, }, nil }
// New creates a journald logger using the configuration passed in on // the context. func New(info logger.Info) (logger.Logger, error) { if !journal.Enabled() { return nil, fmt.Errorf("journald is not enabled on this host") } // parse log tag tag, err := loggerutils.ParseLogTag(info, loggerutils.DefaultTemplate) if err != nil { return nil, err } vars := map[string]string{ "CONTAINER_ID": info.ContainerID[:12], "CONTAINER_ID_FULL": info.ContainerID, "CONTAINER_NAME": info.Name(), "CONTAINER_TAG": tag, } extraAttrs := info.ExtraAttributes(sanitizeKeyMod) for k, v := range extraAttrs { vars[k] = v } return &journald{vars: vars, readers: readerList{readers: make(map[*logger.LogWatcher]*logger.LogWatcher)}}, nil }
// New creates a gelf logger using the configuration passed in on the // context. The supported context configuration variable is gelf-address. func New(info logger.Info) (logger.Logger, error) { // parse gelf address address, err := parseAddress(info.Config["gelf-address"]) if err != nil { return nil, err } // collect extra data for GELF message hostname, err := info.Hostname() if err != nil { return nil, fmt.Errorf("gelf: cannot access hostname to set source field") } // parse log tag tag, err := loggerutils.ParseLogTag(info, loggerutils.DefaultTemplate) if err != nil { return nil, err } extra := map[string]interface{}{ "_container_id": info.ContainerID, "_container_name": info.Name(), "_image_id": info.ContainerImageID, "_image_name": info.ContainerImageName, "_command": info.Command(), "_tag": tag, "_created": info.ContainerCreated, } extraAttrs := info.ExtraAttributes(func(key string) string { if key[0] == '_' { return key } return "_" + key }) for k, v := range extraAttrs { extra[k] = v } rawExtra, err := json.Marshal(extra) if err != nil { return nil, err } // create new gelfWriter gelfWriter, err := gelf.NewWriter(address) if err != nil { return nil, fmt.Errorf("gelf: cannot connect to GELF endpoint: %s %v", address, err) } if v, ok := info.Config["gelf-compression-type"]; ok { switch v { case "gzip": gelfWriter.CompressionType = gelf.CompressGzip case "zlib": gelfWriter.CompressionType = gelf.CompressZlib case "none": gelfWriter.CompressionType = gelf.CompressNone default: return nil, fmt.Errorf("gelf: invalid compression type %q", v) } } if v, ok := info.Config["gelf-compression-level"]; ok { val, err := strconv.Atoi(v) if err != nil { return nil, fmt.Errorf("gelf: invalid compression level %s, err %v", v, err) } gelfWriter.CompressionLevel = val } return &gelfLogger{ writer: gelfWriter, info: info, hostname: hostname, rawExtra: rawExtra, }, nil }