-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds StdoutLogExporter to match (renamed) StdoutSpanExporter (#559)
* Adds StdoutLogExporter to match (renamed) StdoutSpanExporter * Adds deprecation notice to typealias * Renames usage of StdoutSpanExporter
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import Foundation | ||
import OpenTelemetrySdk | ||
|
||
class StdoutLogExporter: LogRecordExporter { | ||
let isDebug: Bool | ||
|
||
init(isDebug: Bool) { | ||
self.isDebug = isDebug | ||
} | ||
|
||
func export(logRecords: [OpenTelemetrySdk.ReadableLogRecord], explicitTimeout: TimeInterval?) -> OpenTelemetrySdk.ExportResult { | ||
if isDebug { | ||
for logRecord in logRecords { | ||
print(String(repeating: "-", count: 40)) | ||
print("Severity: \(String(describing: logRecord.severity))") | ||
print("Body: \(String(describing: logRecord.body))") | ||
print("InstrumentationScopeInfo: \(logRecord.instrumentationScopeInfo)") | ||
print("Timestamp: \(logRecord.timestamp)") | ||
print("ObservedTimestamp: \(String(describing: logRecord.observedTimestamp))") | ||
print("SpanContext: \(String(describing: logRecord.spanContext))") | ||
print("Resource: \(logRecord.resource.attributes)") | ||
print("Attributes: \(logRecord.attributes)") | ||
print(String(repeating: "-", count: 40) + "\n") | ||
} | ||
} else { | ||
do { | ||
let jsonData = try JSONEncoder().encode(logRecords) | ||
if let jsonString = String(data: jsonData, encoding: .utf8) { | ||
print(jsonString) | ||
} | ||
} catch { | ||
print("Failed to serialize LogRecord as JSON: \(error)") | ||
return .failure | ||
} | ||
} | ||
return .success | ||
} | ||
|
||
func forceFlush(explicitTimeout: TimeInterval?) -> OpenTelemetrySdk.ExportResult { | ||
return .success | ||
} | ||
|
||
func shutdown(explicitTimeout: TimeInterval?) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters