1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
4 #ifdef ENABLE_LOGS_PREVIEW
5 # include "opentelemetry/sdk/logs/simple_log_processor.h"
10 OPENTELEMETRY_BEGIN_NAMESPACE
16 * Initialize a simple log processor.
17 * @param exporter the configured exporter where log records are sent
19 SimpleLogProcessor::SimpleLogProcessor(std::unique_ptr
<LogExporter
> &&exporter
)
20 : exporter_(std::move(exporter
))
23 std::unique_ptr
<Recordable
> SimpleLogProcessor::MakeRecordable() noexcept
25 return exporter_
->MakeRecordable();
29 * Batches the log record it receives in a batch of 1 and immediately sends it
30 * to the configured exporter
32 void SimpleLogProcessor::OnReceive(std::unique_ptr
<Recordable
> &&record
) noexcept
34 nostd::span
<std::unique_ptr
<Recordable
>> batch(&record
, 1);
35 // Get lock to ensure Export() is never called concurrently
36 const std::lock_guard
<opentelemetry::common::SpinLockMutex
> locked(lock_
);
38 if (exporter_
->Export(batch
) != sdk::common::ExportResult::kSuccess
)
40 /* Alert user of the failed export */
44 * The simple processor does not have any log records to flush so this method is not used
46 bool SimpleLogProcessor::ForceFlush(std::chrono::microseconds timeout
) noexcept
51 bool SimpleLogProcessor::Shutdown(std::chrono::microseconds timeout
) noexcept
53 // Should only shutdown exporter ONCE.
54 if (!shutdown_latch_
.test_and_set(std::memory_order_acquire
) && exporter_
!= nullptr)
56 return exporter_
->Shutdown(timeout
);
63 OPENTELEMETRY_END_NAMESPACE