Return early if syslog configs are NULL to avoid openlog deprecation

Created on 13 January 2023, about 2 years ago
Updated 4 December 2023, about 1 year ago

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.

🐛 Bug report
Status

Fixed

Version

10.1

Component
Syslog 

Last updated about 5 hours ago

Created by

🇪🇸Spain enchufe Spain

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

  • 🇧🇷Brazil astutonet Sao Paulo, SP

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

  • First commit to issue fork.
  • @arunkumark opened merge request.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India arunkumark Coimbatore

    Rerolled the patch and Created the MR.

  • 🇺🇸United States smustgrave

    Will need a test case showing the issue.

  • 🇩🇪Germany tobiberlin Berlin, Germany

    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

  • Status changed to Needs work almost 2 years ago
  • 🇦🇷Argentina dagmar Argentina

    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 🐛 Return early if syslog configs are NULL to avoid openlog deprecation Fixed 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.

  • 🇩🇪Germany macdev_drupal Wiesbaden

    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'] = '';
    $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.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    29,812 pass
  • 🇺🇸United States mfb San Francisco

    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.

  • 🇺🇸United States mfb San Francisco

    Update steps to reproduce and proposed resolution.

  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    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,...
  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom catch

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

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

  • Status changed to Fixed about 1 year ago
  • 🇦🇲Armenia Alen Simonyan

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

  • 🇦🇲Armenia Alen Simonyan

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

  • 🇺🇸United States mfb San Francisco

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

  • 🇦🇲Armenia Alen Simonyan

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

Production build 0.71.5 2024