Skip to content

Commit 4092ecb

Browse files
committed
fix: frankenphp_log() level parameter must be optional
1 parent 75ccccf commit 4092ecb

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

caddy/caddy_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,3 +1472,31 @@ func TestDd(t *testing.T) {
14721472
"dump123",
14731473
)
14741474
}
1475+
1476+
func TestLog(t *testing.T) {
1477+
tester := caddytest.NewTester(t)
1478+
tester.InitServer(`
1479+
{
1480+
skip_install_trust
1481+
admin localhost:2999
1482+
}
1483+
1484+
http://localhost:`+testPort+` {
1485+
log {
1486+
output stdout
1487+
format json
1488+
}
1489+
1490+
root ../testdata
1491+
php_server {
1492+
worker ../testdata/log-frankenphp_log.php
1493+
}
1494+
}
1495+
`, "caddyfile")
1496+
1497+
tester.AssertGetResponse(
1498+
"http://localhost:"+testPort+"/log-frankenphp_log.php?i=0",
1499+
http.StatusOK,
1500+
"",
1501+
)
1502+
}

frankenphp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,10 @@ PHP_FUNCTION(frankenphp_log) {
554554
zend_long level = 0;
555555
zval *context = NULL;
556556

557-
ZEND_PARSE_PARAMETERS_START(2, 3)
557+
ZEND_PARSE_PARAMETERS_START(1, 3)
558558
Z_PARAM_STR(message)
559-
Z_PARAM_LONG(level)
560559
Z_PARAM_OPTIONAL
560+
Z_PARAM_LONG(level)
561561
Z_PARAM_ARRAY(context)
562562
ZEND_PARSE_PARAMETERS_END();
563563

frankenphp_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ func testLog_frankenphp_log(t *testing.T, opts *testOptions) {
447447

448448
logs := buf.String()
449449
for _, message := range []string{
450+
`level=INFO msg="default level message"`,
450451
fmt.Sprintf(`level=DEBUG msg="some debug message %d" "key int"=1`, i),
451452
fmt.Sprintf(`level=INFO msg="some info message %d" "key string"=string`, i),
452453
fmt.Sprintf(`level=WARN msg="some warn message %d"`, i),

testdata/log-frankenphp_log.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
require_once __DIR__.'/_executor.php';
44

5+
frankenphp_log("default level message");
6+
57
return function () {
68
frankenphp_log("some debug message {$_GET['i']}", FRANKENPHP_LOG_LEVEL_DEBUG, [
79
"key int" => 1,

0 commit comments

Comments
 (0)