If I call a php file not related to the PHP Maker project with a deliberate error in code like:
$ii = bogusFunction(); //this function is not defined
…the error is logged to the php_errors.log. This shows that php.ini in my webserver is correctly set to log errors.
In the exact same webserver, If I put that piece of code somewhere it a PHP file belonging to the project (like inside a rowRendering function), the error is shown (if in development environment), or I get a generic error (in production environment). Either way, nothing gets logged to php_errors.log. No matter if debug is enabled or disabled.
I know there are other error logging options like the “Log error to file” advanced setting, but I specifically need PHP errors to be logged to the standard file regardless.
I’m using the latest PHP 8.1 in IIS and the latest v2025. Help appreciated.
PHPMaker uses the popular Monolog as logger, you may change the definition of the logger by Container_Build server event, e.g. (v2025)
function Container_Build(ContainerBuilder $builder): void{
$builder->addDefinitions([
'app.logger' => \DI\factory(function (\Psr\Container\ContainerInterface $c) {
$logger = new \Monolog\Logger('log');
// Original file handler
// Note: Update the log folder, by default it is 'log/log.log' where 'log/' is the log path you set in your project
$fileHandler = new \Monolog\Handler\RotatingFileHandler('path/to/log.log');
$logger->pushHandler($fileHandler);
// Add your additional handler, e.g.
$errorHandler = new \Monolog\Handler\ErrorLogHandler(\Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM);
$logger->pushHandler($errorHandler);
return $logger;
}),
]);
}
That works, thanks a lot!
However, I’d like to lower the loglevel in production, as logging all the debugging messages (SQL queries and such) bloats the logfiles too much.
I tried lowering the loglevel to WARNING, but I’m still getting debug messages logged:
$builder->addDefinitions([
'app.logger' => \DI\factory(function (\Psr\Container\ContainerInterface $c) {
$logger = new \Monolog\Logger('log');
// Original file handler
// Note: Update the log folder, by default it is 'log/log.log' where 'log/' is the log path you set in your project
$fileHandler = new \Monolog\Handler\RotatingFileHandler(ServerVar('error_log'), \Monolog\Logger::WARNING);
$logger->pushHandler($fileHandler);
// Add your additional handler, e.g.
$errorHandler = new \Monolog\Handler\ErrorLogHandler(\Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM);
$logger->pushHandler($errorHandler);
return $logger;
}),
]);
How do I just keep the PHP Maker original logs (rotating log file in log folder), but lower the loglevel in production (and debug disabled) to WARNING? I can’t find a way to do that.
My whole objective was to have some level of error logging in production, as monolog by default disables logging to php_errors.log (as defined in php.ini).
In the end, I opted to keep the original log location and handler. I just lower the level when not in debug:
//Reduce logging level when not in debug. "Log error and SQL to file" advanced setting must be enabled
if (!IsDebug()) $builder->addDefinitions([
'app.logger' => \DI\factory(function (\Psr\Container\ContainerInterface $c) {
$logger = new \Monolog\Logger('log');
// Note: Update the log level, by default it is DEBUG.
// Levels: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY
$fileHandler = new \Monolog\Handler\RotatingFileHandler('log/log.log', 0, \Monolog\Logger::WARNING);
$logger->pushHandler($fileHandler);
return $logger;
}),
]);