fix: frankenphp_log() level parameter must be optional

This commit is contained in:
Kévin Dunglas
2025-12-19 16:03:42 +01:00
parent 75ccccf1b2
commit 4092ecb5b5
4 changed files with 33 additions and 2 deletions

View File

@@ -1472,3 +1472,31 @@ func TestDd(t *testing.T) {
"dump123",
)
}
func TestLog(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
{
skip_install_trust
admin localhost:2999
}
http://localhost:`+testPort+` {
log {
output stdout
format json
}
root ../testdata
php_server {
worker ../testdata/log-frankenphp_log.php
}
}
`, "caddyfile")
tester.AssertGetResponse(
"http://localhost:"+testPort+"/log-frankenphp_log.php?i=0",
http.StatusOK,
"",
)
}

View File

@@ -554,10 +554,10 @@ PHP_FUNCTION(frankenphp_log) {
zend_long level = 0;
zval *context = NULL;
ZEND_PARSE_PARAMETERS_START(2, 3)
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STR(message)
Z_PARAM_LONG(level)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(level)
Z_PARAM_ARRAY(context)
ZEND_PARSE_PARAMETERS_END();

View File

@@ -447,6 +447,7 @@ func testLog_frankenphp_log(t *testing.T, opts *testOptions) {
logs := buf.String()
for _, message := range []string{
`level=INFO msg="default level message"`,
fmt.Sprintf(`level=DEBUG msg="some debug message %d" "key int"=1`, i),
fmt.Sprintf(`level=INFO msg="some info message %d" "key string"=string`, i),
fmt.Sprintf(`level=WARN msg="some warn message %d"`, i),

View File

@@ -2,6 +2,8 @@
require_once __DIR__.'/_executor.php';
frankenphp_log("default level message");
return function () {
frankenphp_log("some debug message {$_GET['i']}", FRANKENPHP_LOG_LEVEL_DEBUG, [
"key int" => 1,