diff --git a/ChangeLog.md b/ChangeLog.md index ab50f7e0..1b7026e3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,10 @@ Web change log ## ?.?.? / ????-??-?? +* Make passing an empty value for logging like such: `xp web -l "" [...]` + disable logging. + (@thekid) + ## 4.4.2 / 2024-08-26 * Fixed accessing params from a request with content-type, but without diff --git a/src/main/php/web/logging/Sink.class.php b/src/main/php/web/logging/Sink.class.php index c501d0cd..9a22283f 100755 --- a/src/main/php/web/logging/Sink.class.php +++ b/src/main/php/web/logging/Sink.class.php @@ -31,7 +31,7 @@ public function target() { return nameof($this); } public static function of($arg) { if ('-' === $arg) { return new ToConsole(); - } else if (null === $arg) { + } else if (null === $arg || '' === $arg) { return null; } else if (is_callable($arg)) { return new ToFunction($arg); diff --git a/src/test/php/web/unittest/LoggingTest.class.php b/src/test/php/web/unittest/LoggingTest.class.php index 1e616656..02846a2b 100755 --- a/src/test/php/web/unittest/LoggingTest.class.php +++ b/src/test/php/web/unittest/LoggingTest.class.php @@ -34,6 +34,11 @@ public function no_logging_target() { Assert::equals('(no logging)', (new Logging(null))->target()); } + #[Test, Values([null, ''])] + public function no_logging_target_of($target) { + Assert::equals('(no logging)', Logging::of($target)->target()); + } + #[Test, Values(from: 'arguments')] public function log($expected, $error) { $req= new Request(new TestInput('GET', '/'));