Problem/Motivation
I recently upgraded my Drupal system to 9.5.1 with PHP 8.1 (I have updated both) and encountered the following messages when logging in after reinstalling the site in local and test environments:
Deprecated: openlog(): Passing null to parameter #1 ($prefix) of type string is deprecated in /var/www/html/web/core/modules/syslog/src/Logger/SysLog.php on line 56
Deprecated: openlog(): Passing null to parameter #3 ($facility) of type int is deprecated in /var/www/html/web/core/modules/syslog/src/Logger/SysLog.php on line 56
I have detected that this error is due to the fact that inside the syslog module, the Logger openConnection() function (/core/modules/syslog/src/Logger/SysLog.php) generates a deprecation warning by not defining the values of the PHP function openlog().
Steps to reproduce
Install Drupal with PHP 8.1; install syslog module; run drush config:delete syslog.settings identity or drush config:delete syslog.settings facility, and login as administrator.
Or install Drupal with PHP 8.1; override $config['syslog.settings']['format'] with a non-empty value in settings.php, but do not set identity or facility, and install syslog module.
In either case, this debug-level log message will appear: Deprecated function: openlog(): Passing null to parameter #3 ($facility) of type int is deprecated in Drupal\syslog\Logger\SysLog->openConnection() (line 56 of core/modules/syslog/src/Logger/SysLog.php)
Proposed resolution
Do not connect to syslog if the identity or facility configs are missing.
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | 3333215.patch | 571 bytes | alen simonyan |
| #29 | 3333215.patch | 577 bytes | alen simonyan |
| #22 | 3333215-22.patch | 2.17 KB | mfb |
Issue fork drupal-3333215
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
enchufeComment #3
enchufeComment #4
enchufeComment #5
enchufeSorry, I'm re-uploading the patch without the duplicated ".patch".
Comment #6
enchufeComment #7
nitin shrivastava commentedpatch for drupal 10.1.x
Comment #8
cilefen commentedI am updating tags according to the guidelines.
This is opened as a support request, which means code offered here will not be incorporated into Drupal. Is it actually a bug report? If so, can you please list the steps to reproduce it? Which module is passing nulls?
Comment #9
enchufeComment #10
enchufe#8
Sorry, I am relatively new to the Drupal community and I am still learning the guidelines, I have already updated the issue with more information.
Comment #11
enchufeFixed patch for drupal 9.5.x
Comment #12
mfbIt's not expected for the prefix (aka identity) or facility config to be NULL, as these are created as string and integer configs, respectively. That said, it is technically possible for a config to be NULL since it could be forcibly deleted e.g. via drush.
I would say if either of these configs are unexpectedly NULL, it's best to not call openlog() at all, and log a more severe warning or error message rather than this deprecated notice. But if this is a super rare scenario then not sure it's worth spending the time to work on a patch..
Comment #13
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #14
astutonetI had the same issue described here in a dev site and patch in #11 solved the question
Comment #17
arunkumarkRerolled the patch and Created the MR.
Comment #18
smustgrave commentedWill need a test case showing the issue.
Comment #19
tobiberlinI had the same error on my page after updating to PHP 8.1 and Drupal 9.5.7 when I submitted a webform. the patch in #11 solved the problem
Comment #20
dagmarI tried to replicate this with Drupal 9.5.x and 10.x. In both scenarios, the default value for 'identity' is set to drupal. And this has been the case since 2012 according to git log.
If you submit the form UI for syslog with no identity, it fallbacks to an empty string.
As @mfb said https://www.drupal.org/project/drupal/issues/3333215#comment-14868399 the only way this can happen is by either, editing the identity using drush cedit, or by manually removing the identity value from the config file and running drush config sync.
This seems more a won't fix to me than forcing the value of openlog.
Comment #21
macdev_drupal commentedHave the same error after updating to php 8.1.20 and drupal core 9.5.8
We set the identiy from settings.php, as we run more than 100 sites with the same drupal build, with:
$config['system.logging']['error_level'] = 'all';
$config['syslog.settings']['identity'] = 'replaced name of current site';
$config['syslog.settings']['format'] = '!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message';
After a drush cr is run the first visitor would se the red deprecation warning.
Therefore I would upvote for this to be fixed in core.
Comment #22
mfbIt sounds like folks are hitting edge cases where format is set, but facility or identity (prefix) is not set. Syslog module only checks if format exists before logging, but not the other configs. So if you have format set, but not facility or identity (prefix), then you hit this "deprecated" message.
Here's a patch w/ the extra logic to also check facility and identity (prefix) before logging.
Comment #23
mfbUpdate steps to reproduce and proposed resolution.
Comment #24
smustgrave commentedRan the test locally without the fix and got
Failed asserting that file "vfs://root/sites/simpletest/62868829/files/syslog.log" does not exist.Additional check seems to be good and matches issue summary.
Comment #27
catchCommitted/pushed to 11.x and cherry-picked to 10.1.x, thanks!
Comment #29
alen simonyan commentedSomehow it will not apply for version ^10.1 and I have to generate new patch.
Comment #30
alen simonyan commentedSorry, uploaded wrong patch, here is the right one.
Comment #31
mfb@Alen Simonyan this issue was already resolved in the 10.1 branch, so you don't need to apply a patch
Comment #32
alen simonyan commentedAhh, ok, thanks @mfb, didn't notice