log4php generates a Deprecated: fwrite(): Passing null to parameter #2 ($data) of type string is deprecated in D:inclog4phpappendersLoggerAppenderFile.php on line 137
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="default" class="LoggerAppenderFile">
<layout class="LoggerLayoutSimple" />
<param name="file" value="test.log" />
<param name="append" value="true" />
</appender>
<root>
<appender_ref ref="default" />
</root>
</configuration>
and initialization
require ROOT . "/inc/log4php/Logger.php";
Logger::configure( ROOT . 'log-config.xml' );
$logger = Logger::getLogger( 'main' );
define( 'LOG', $logger );
LOG->debug( 'utils.php' );
What would be the proper way to start the log4php logger? I copied the settings from the documentation.
2
Answers
The official log4php project is now old and inactive, but there exists a fork that added PHP 8 compatibility (as you can see here):
If this is the only message you’re getting, one option is to ignore the message, for now. Don’t ignore it forever, but don’t panic right now.
A deprecation notice is not an error; it is a message warning you that a future version of PHP will throw an error on that piece of code. Due to PHP’s compatibility policy, that will be PHP 9.0 at the earliest. The entire purpose of such messages is to give you time to fix them.
From the context you’ve given, the message is not about how you’re calling the library, it’s about how the library is handling some situation. So there are two possibilities:
Note that your application might treat this notice as though it as an error, by setting a custom "error handler" – some frameworks do this by default on development mode. Consider whether you think that is a useful configuration, and whether fixing messages like this as early as possible is the right priority for your time.