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.

Issue fork drupal-3333215

Command icon 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

enchufe created an issue. See original summary.

enchufe’s picture

Title: Forcing data conversion to avoid open deprecation » Forcing data conversion to avoid openlog deprecation
enchufe’s picture

Issue summary: View changes
enchufe’s picture

enchufe’s picture

Sorry, I'm re-uploading the patch without the duplicated ".patch".

enchufe’s picture

Title: Forcing data conversion to avoid openlog deprecation » Force data conversion to avoid openlog deprecation
nitin shrivastava’s picture

StatusFileSize
new688 bytes

patch for drupal 10.1.x

cilefen’s picture

Priority: Major » Normal
Status: Needs review » Postponed (maintainer needs more info)
Issue tags: -Drupal 9 compatibility, -deprecated, -@deprecated, -logger, -Syslog, -syslog module

I 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?

enchufe’s picture

Category: Support request » Bug report
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review
enchufe’s picture

#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.

enchufe’s picture

StatusFileSize
new698 bytes

Fixed patch for drupal 9.5.x

mfb’s picture

It'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..

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The 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.

astutonet’s picture

I had the same issue described here in a dev site and patch in #11 solved the question

arunkumark made their first commit to this issue’s fork.

arunkumark’s picture

Status: Needs work » Needs review

Rerolled the patch and Created the MR.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

Will need a test case showing the issue.

tobiberlin’s picture

I 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

dagmar’s picture

I 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.

macdev_drupal’s picture

Have 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.

mfb’s picture

Version: 9.5.x-dev » 11.x-dev
Assigned: enchufe » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.17 KB

It 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.

mfb’s picture

Title: Force data conversion to avoid openlog deprecation » Return early if syslog configs are NULL to avoid openlog deprecation
Issue summary: View changes

Update steps to reproduce and proposed resolution.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Ran 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.

  • catch committed 9ae6dbd4 on 10.1.x
    Issue #3333215 by enchufe, arunkumark, mfb, Nitin shrivastava,...

  • catch committed 5ce13375 on 11.x
    Issue #3333215 by enchufe, arunkumark, mfb, Nitin shrivastava,...
catch’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 10.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

alen simonyan’s picture

StatusFileSize
new577 bytes

Somehow it will not apply for version ^10.1 and I have to generate new patch.

alen simonyan’s picture

StatusFileSize
new571 bytes

Sorry, uploaded wrong patch, here is the right one.

mfb’s picture

@Alen Simonyan this issue was already resolved in the 10.1 branch, so you don't need to apply a patch

alen simonyan’s picture

Ahh, ok, thanks @mfb, didn't notice