Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/API/Behavior/Internal/LogWriter/TriggerErrorLogWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\API\Behavior\Internal\LogWriter;

class TriggerErrorLogWriter implements LogWriterInterface
{
#[\Override]
public function write($level, string $message, array $context): void
{
trigger_error(Formatter::format($level, $message, $context));
}
}
3 changes: 3 additions & 0 deletions src/API/Behavior/Internal/LogWriterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OpenTelemetry\API\Behavior\Internal\LogWriter\NoopLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\Psr3LogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\StreamLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\TriggerErrorLogWriter;
use OpenTelemetry\API\Instrumentation\ConfigurationResolver;
use OpenTelemetry\API\LoggerHolder;

Expand Down Expand Up @@ -39,6 +40,8 @@ public function create(): LogWriterInterface
return new ErrorLogWriter();
case 'error_log':
return new ErrorLogWriter();
case 'trigger_error':
return new TriggerErrorLogWriter();
default:
if ($logger) {
return new Psr3LogWriter($logger);
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/API/Behavior/Internal/LogWriterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use OpenTelemetry\API\Behavior\Internal\LogWriter\NoopLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\Psr3LogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\StreamLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\TriggerErrorLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriterFactory;
use OpenTelemetry\API\LoggerHolder;
use OpenTelemetry\Tests\TestState;
Expand Down Expand Up @@ -41,6 +42,7 @@ public static function logDestinationProvider(): array
{
return [
['error_log', ErrorLogWriter::class],
['trigger_error', TriggerErrorLogWriter::class],
['stdout', StreamLogWriter::class],
['stderr', StreamLogWriter::class],
['none', NoopLogWriter::class],
Expand All @@ -53,4 +55,5 @@ public function test_psr3_log_destination(): void
LoggerHolder::set($this->createMock(LoggerInterface::class));
$this->assertInstanceOf(Psr3LogWriter::class, (new LogWriterFactory())->create());
}

Comment thread
SoulofAkuma marked this conversation as resolved.
Outdated
}
Loading