[ 
https://issues.apache.org/jira/browse/THRIFT-6009?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Volodymyr Panivko updated THRIFT-6009:
--------------------------------------
    Description: 
h3. Problem

The PHP socket transports ({{TSocket}}, {{TSSLSocket}}, {{TSocketPool}}) 
accepted a {{$debugHandler}} typed {{callable|string|null}}, defaulting to 
{{'error_log'}}, invoked via {{call_user_func()}}. There was no way to wire in 
a {{Psr\Log\LoggerInterface}} directly. Additionally, 
{{TSSLServerSocket::getSSLHost()}} was marked {{@deprecated}} in its docblock 
but emitted no runtime warning.

h3. What was done

* Added {{psr/log: ^1.0 || ^2.0 || ^3.0}} to {{composer.json}}. Thrift is a 
consumer of the interface, so the multi-major constraint is safe.
* Widened {{$debugHandler}} on the three transports to 
{{LoggerInterface|callable|string|null}}.
* Introduced a single {{protected log(string $level, string $message)}} helper 
on {{TSocket}} that routes diagnostics:
** {{LoggerInterface}} — always invoked; the logger filters by level. 
Per-call-site mapping in {{TSocketPool::open()}}: {{DEBUG}} for 
retry-interval-elapsed, {{WARNING}} for marking host down, {{ERROR}} for 
connection failures and all-hosts-down.
** legacy callable / string — gated by {{setDebug()}} for BC; constructor emits 
{{E_USER_DEPRECATED}}.
** no handler + {{setDebug(true)}} — falls back to {{error_log()}}, preserving 
master's stderr output.
* {{setDebug()}} retained (gates the legacy path) but marked {{@deprecated}} 
and emits {{E_USER_DEPRECATED}}. No effect on the PSR-3 path.
* {{TSSLServerSocket::getSSLHost()}} now emits {{E_USER_DEPRECATED}} at runtime.
* {{test/php/TestClient.php}} demonstrates the new API by injecting a small 
PSR-3 {{StderrLogger}}.
* Shared {{Test\Thrift\Unit\Lib\UserDeprecationCapture}} test trait factors out 
the {{E_USER_DEPRECATED}} capture pattern.

h3. Backwards compatibility

All three common runtime cases preserve master behaviour:
* no handler + no {{setDebug}} → silent (as before)
* no handler + {{setDebug(true)}} → writes via {{error_log()}} (as before)
* legacy callable / string + {{setDebug(true)}} → callable invoked (as before; 
with deprecation warning)

h3. PR

https://github.com/apache/thrift/pull/3490

  was:
h3. Problem

The PHP socket transports ({{TSocket}}, {{TSSLSocket}}, {{TSocketPool}}) accept 
a {{$debugHandler}} typed {{callable|string|null}}, defaulting to 
{{'error_log'}}, invoked via {{call_user_func()}}. This forces users to wrap 
PSR-3 loggers in closures and prevents per-call-site log levels.

Additionally, {{TSSLServerSocket::getSSLHost()}} is marked {{@deprecated}} in 
its docblock but emits no runtime warning, so consumers cannot discover they 
are on a path slated for removal.

h3. Proposed change

* Add {{psr/log: ^1.0 || ^2.0 || ^3.0}} to {{composer.json}} (Thrift is a 
consumer of the interface, not an implementer, so the multi-major constraint is 
safe).
* Widen {{$debugHandler}} on {{TSocket}}, {{TSSLSocket}}, {{TSocketPool}} to 
{{Psr\Log\LoggerInterface|callable|string|null}}.
* Use {{NullLogger}} as the default; map call sites to {{Psr\Log\LogLevel}} 
constants ({{DEBUG}} for retry-interval-elapsed, {{WARNING}} for 
marking-host-down, {{ERROR}} for connection failures and all-hosts-down).
* Emit {{E_USER_DEPRECATED}} via {{trigger_error()}} when a string handler is 
passed (legacy form). Existing callable handlers continue to work unchanged.
* Emit {{E_USER_DEPRECATED}} from {{TSSLServerSocket::getSSLHost()}} at runtime.

h3. Behavior change

The default no-handler path changes from PHP's {{error_log}} to {{NullLogger}} 
(silent). Pre-1.0 release license — users wanting the old behavior pass a 
{{LoggerInterface}} or a closure wrapping {{error_log}}.

h3. Tests

Unit-test coverage for all new paths (LoggerInterface dispatch with per-site 
levels, deprecation trigger on string handler, default-path silence, getSSLHost 
deprecation).


> Add PSR-3 logger support and runtime deprecation warnings to PHP transports
> ---------------------------------------------------------------------------
>
>                 Key: THRIFT-6009
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6009
>             Project: Thrift
>          Issue Type: Improvement
>          Components: PHP - Library
>            Reporter: Volodymyr Panivko
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> h3. Problem
> The PHP socket transports ({{TSocket}}, {{TSSLSocket}}, {{TSocketPool}}) 
> accepted a {{$debugHandler}} typed {{callable|string|null}}, defaulting to 
> {{'error_log'}}, invoked via {{call_user_func()}}. There was no way to wire 
> in a {{Psr\Log\LoggerInterface}} directly. Additionally, 
> {{TSSLServerSocket::getSSLHost()}} was marked {{@deprecated}} in its docblock 
> but emitted no runtime warning.
> h3. What was done
> * Added {{psr/log: ^1.0 || ^2.0 || ^3.0}} to {{composer.json}}. Thrift is a 
> consumer of the interface, so the multi-major constraint is safe.
> * Widened {{$debugHandler}} on the three transports to 
> {{LoggerInterface|callable|string|null}}.
> * Introduced a single {{protected log(string $level, string $message)}} 
> helper on {{TSocket}} that routes diagnostics:
> ** {{LoggerInterface}} — always invoked; the logger filters by level. 
> Per-call-site mapping in {{TSocketPool::open()}}: {{DEBUG}} for 
> retry-interval-elapsed, {{WARNING}} for marking host down, {{ERROR}} for 
> connection failures and all-hosts-down.
> ** legacy callable / string — gated by {{setDebug()}} for BC; constructor 
> emits {{E_USER_DEPRECATED}}.
> ** no handler + {{setDebug(true)}} — falls back to {{error_log()}}, 
> preserving master's stderr output.
> * {{setDebug()}} retained (gates the legacy path) but marked {{@deprecated}} 
> and emits {{E_USER_DEPRECATED}}. No effect on the PSR-3 path.
> * {{TSSLServerSocket::getSSLHost()}} now emits {{E_USER_DEPRECATED}} at 
> runtime.
> * {{test/php/TestClient.php}} demonstrates the new API by injecting a small 
> PSR-3 {{StderrLogger}}.
> * Shared {{Test\Thrift\Unit\Lib\UserDeprecationCapture}} test trait factors 
> out the {{E_USER_DEPRECATED}} capture pattern.
> h3. Backwards compatibility
> All three common runtime cases preserve master behaviour:
> * no handler + no {{setDebug}} → silent (as before)
> * no handler + {{setDebug(true)}} → writes via {{error_log()}} (as before)
> * legacy callable / string + {{setDebug(true)}} → callable invoked (as 
> before; with deprecation warning)
> h3. PR
> https://github.com/apache/thrift/pull/3490



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to