Fix & clean up examples (#78)

This commit is contained in:
Christopher Hertel 2025-09-24 21:50:06 +02:00 • committed by GitHub
commit 8defd9b17f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,10 +16,7 @@ use Psr\Log\LoggerInterface;
require_once dirname(__DIR__).'/vendor/autoload.php';
set_exception_handler(function (Throwable $t): never {
fwrite(\STDERR, "[MCP SERVER CRITICAL ERROR]\n");
fwrite(\STDERR, 'Error: '.$t->getMessage()."\n");
fwrite(\STDERR, 'File: '.$t->getFile().':'.$t->getLine()."\n");
fwrite(\STDERR, $t->getTraceAsString()."\n");
logger()->critical('Uncaught exception: '.$t->getMessage(), ['exception' => $t]);
exit(1);
});
@ -42,9 +39,9 @@ function logger(): LoggerInterface
([] === $context || !$debug) ? '' : json_encode($context),
);
if ($_SERVER['FILE_LOG'] ?? false) {
if (($_SERVER['FILE_LOG'] ?? false) || !defined('STDERR')) {
file_put_contents('dev.log', $logMessage, \FILE_APPEND);
} elseif (defined('STDERR')) {
} else {
fwrite(\STDERR, $logMessage);
}
}