| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package normal |
| 5 |
|
| 6 |
import ( |
| 7 |
"bytes" |
| 8 |
"fmt" |
| 9 |
"strings" |
| 10 |
|
| 11 |
"go.opentelemetry.io/collector/pdata/plog" |
| 12 |
) |
| 13 |
|
| 14 |
type normalLogsMarshaler struct{} |
| 15 |
|
| 16 |
|
| 17 |
var _ plog.Marshaler = normalLogsMarshaler{} |
| 18 |
|
| 19 |
|
| 20 |
func NewNormalLogsMarshaler() plog.Marshaler { |
| 21 |
return normalLogsMarshaler{} |
| 22 |
} |
| 23 |
|
| 24 |
func (normalLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) { |
| 25 |
var buffer bytes.Buffer |
| 26 |
for i := 0; i < ld.ResourceLogs().Len(); i++ { |
| 27 |
resourceLog := ld.ResourceLogs().At(i) |
| 28 |
|
| 29 |
buffer.WriteString(fmt.Sprintf("ResourceLog #%d%s%s\n", i, writeResourceDetails(resourceLog.SchemaUrl()), writeAttributesString(resourceLog.Resource().Attributes()))) |
| 30 |
|
| 31 |
for j := 0; j < resourceLog.ScopeLogs().Len(); j++ { |
| 32 |
scopeLog := resourceLog.ScopeLogs().At(j) |
| 33 |
|
| 34 |
buffer.WriteString(fmt.Sprintf("ScopeLog #%d%s%s\n", i, writeScopeDetails(scopeLog.Scope().Name(), scopeLog.Scope().Version(), scopeLog.SchemaUrl()), writeAttributesString(scopeLog.Scope().Attributes()))) |
| 35 |
|
| 36 |
for k := 0; k < scopeLog.LogRecords().Len(); k++ { |
| 37 |
logRecord := scopeLog.LogRecords().At(k) |
| 38 |
logAttributes := writeAttributes(logRecord.Attributes()) |
| 39 |
|
| 40 |
logString := fmt.Sprintf("%s %s", logRecord.Body().AsString(), strings.Join(logAttributes, " ")) |
| 41 |
buffer.WriteString(logString) |
| 42 |
buffer.WriteString("\n") |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
return buffer.Bytes(), nil |
| 47 |
} |