forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
formatter.go
29 lines (24 loc) · 944 Bytes
/
formatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package syslogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/syslogexporter"
import (
"go.opentelemetry.io/collector/pdata/plog"
)
func createFormatter(protocol string, octetCounting bool) formatter {
if protocol == protocolRFC5424Str {
return newRFC5424Formatter(octetCounting)
}
return newRFC3164Formatter()
}
type formatter interface {
format(plog.LogRecord) string
}
// getAttributeValueOrDefault returns the value of the requested log record's attribute as a string.
// If the attribute was not found, it returns the provided default value.
func getAttributeValueOrDefault(logRecord plog.LogRecord, attributeName string, defaultValue string) string {
value := defaultValue
if attributeValue, found := logRecord.Attributes().Get(attributeName); found {
value = attributeValue.AsString()
}
return value
}