protected function toLogLoggableTraitImpl()

in agent/php/ElasticApm/Impl/Log/LoggableTrait.php [61:103]


    protected function toLogLoggableTraitImpl(LogStreamInterface $stream, array $customPropValues = []): void
    {
        $nameToValue = $customPropValues;

        $classNameToLog = static::classNameToLog();
        if ($classNameToLog !== null) {
            $nameToValue[LogConsts::TYPE_KEY] = $classNameToLog;
        }

        try {
            $currentClass = new ReflectionClass(get_class($this));
        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (ReflectionException $ex) {
            $stream->toLogAs(
                LoggingSubsystem::onInternalFailure('Failed to reflect', ['class' => get_class($this)], $ex)
            );
            return;
        }

        $propertiesExcludedFromLog = array_merge(static::propertiesExcludedFromLog(), static::defaultPropertiesExcludedFromLog());
        while (true) {
            foreach ($currentClass->getProperties() as $reflectionProperty) {
                if ($reflectionProperty->isStatic()) {
                    continue;
                }

                $reflectionProperty->setAccessible(true);
                $propName = $reflectionProperty->name;
                if (array_key_exists($propName, $customPropValues)) {
                    continue;
                }
                if (in_array($propName, $propertiesExcludedFromLog, /* strict */ true)) {
                    continue;
                }
                $nameToValue[$propName] = $reflectionProperty->getValue($this);
            }
            $currentClass = $currentClass->getParentClass();
            if ($currentClass === false) {
                break;
            }
        }

        $stream->toLogAs($nameToValue);
    }