Remove dependency of "file_system" service on "logger"

Created on 21 December 2016, almost 8 years ago
Updated 27 June 2024, 5 months ago

Problem/Motivation

Currently, file_system service depends on three other services:

  file_system:
    class: Drupal\Core\File\FileSystem
    arguments: ['@stream_wrapper_manager', '@settings', '@logger.channel.file']

Inside of Drupal\Core\File\FileSystem class, instance of logger is used only once in the chmod() method to log error when chmod() PHP function returns FALSE.

Not only this is a side effect, but an instance of logger.channel.file contains references to other services: requests stack, current user object. And from the source of Drupal\Core\Logger\LoggerChannel::log() method, it looks like it can even execute a database query.

Logger makes dependency tree of file_system service unnecessary complicated, and I would expect such a low-level service to have as little side-effects as possible.

Remaining tasks

None

User interface changes

None.

API changes

Change of Drupal\Core\File\FileSystem::__construct() signature.
FileSystem no longer logs any errors. This is up to the caller.

Data model changes

None.

πŸ“Œ Task
Status

Fixed

Version

10.3 ✨

Component
File systemΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡¨πŸ‡¦Canada 20th

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

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.

  • last update over 1 year ago
    Patch Failed to Apply
  • πŸ‡·πŸ‡ΊRussia Chi

    Inside of Drupal\Core\File\FileSystem class, instance of logger is used only once in the chmod() method to log error when chmod() PHP function returns FALSE.

    The issues is quite old. At the moment, file system makes a heavy use of the logger.

  • First commit to issue fork.
  • Merge request !43922838474-11.x β†’ (Open) created by rpayanm
  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    29,814 pass
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΎUruguay rpayanm

    Please review.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    NW for MR feedback above.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I think given that we have code like

    if (is_dir($directory) && !is_writable($directory) && !$file_system->chmod($directory)) {
    

    we should go for solution 2 as the less disruptive for now. And leave it up to the calling code to log if necessary. In the above example, logging is actually not appropriate as this is used to inform the user.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Hiding patches as we have an MR now.

  • Status changed to Needs review 10 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I've gone for a halfway house for #40 and added $throw to \Drupal\Core\File\FileSystem::chmod() so the caller is in control.

    I don't think there are any use-cases for $throw in core but I've ensured there is test coverage.

  • Pipeline finished with Success
    10 months ago
    #80734
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Updated issue summary with latest changes.

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    I updated the change record to more completely describe the impacts of logging being removed. Now I realize it needs a bit more work as I see Alexpott added an additional new change record, so they are partially redundant.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Why do we need the $throw argument, the caller can detect failure via the return value already?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @longwave yeah I went that way originally but then got cold feet when deleting the exception.. but I agree - let's remove $throw.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    If we think it's worth cleaning up, perhaps in a followup we can add deprecations in all the cases we currently return FALSE and notify users that we will start throwing exceptions instead in the next major.

  • Pipeline finished with Success
    10 months ago
    #80807
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @longwave I don't think we want that though - in the case of chod there are times that throwing an exception would lead to way more complex calling code.

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    @alexpott I'd say it should still be mentioned in the change record that logging is removed from those other methods, not just chmod. But you removed my mention of those. This is relevant if the calling code caught the exception and assumed an error was already logged by the file_system service.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @mfb I've listed the public method that no longer log in the CR and detailed that it is the callers responsibility to log if any method results in FALSE or throws an exception.

  • Status changed to Needs work 10 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia
  • Status changed to Needs review 10 months ago
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Fixed deprecation, also fixed a nit in the docblock.

    πŸ“Œ Inject services into LoggerChannelFactory RTBC is somewhat related, there is special code in LoggerChannelFactory to handle the case where the injected dependencies are not present (during the installer), once this dependency is gone I think that can also be removed.

  • πŸ‡³πŸ‡±Netherlands spokje

    Tagging with Needs followup for #52 πŸ“Œ Remove dependency of "file_system" service on "logger" Needs work

  • Status changed to RTBC 10 months ago
  • πŸ‡³πŸ‡±Netherlands spokje

    Code changes make sense and are primarily removing logging/loggers and altering comments about logging/loggers.
    Checked CR and that mentions all methods involved in not being logged any more.
    Tests are green.

    For me this is RTBC.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    The followup isn't really needed until both issues land, just they overlap a bit, so we can probably fix it directly in whichever lands second - removing the tag.

  • πŸ‡³πŸ‡±Netherlands spokje

    I'm glad somebody is an optimist and is sure we'll remember ;)

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Well it's only a bit of dead code if we don't. And πŸ“Œ Fix install container definition of StreamWrapperManager Needs review is making me think that this might not even get used...

  • πŸ‡ΊπŸ‡ΈUnited States SocialNicheGuru

    I applied this πŸ“Œ Remove dependency of "file_system" service on "logger" Needs work I get this:
    Circular reference detected for service "workspaces.manager", path: "scheduler.manager -> dat
    e.formatter -> workspaces.manager -> logger.channel.workspaces -> logger.factory -> logger.syslog".

  • πŸ‡³πŸ‡±Netherlands spokje

    #58: You might have c/p a wrong issue link (it is to this very issue) in there?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @SocialNicheGuru we're going to need some more information about how to reproduce what you are seeing. I have installed:

    1. Standard profile
    2. Enabled scheduler, workspaces, filecache
    3. Configured filecache
    4. Enabled syslog
    5. Boom things are broken
    6. Applied this MR and cleared the cached - things are fixed

    I can create the datetime.formatter and workspaces.manager services just fine after this. But my datetime.formatter does not depend on workspaces.manager - how is that happening on your install?

    This MR is definitely resolving a bug.

  • Status changed to Needs work 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    One question on the MR.

  • Status changed to Needs review 9 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia
  • Status changed to RTBC 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @catch's feedback has been addressed. This looks good to go now. Thanks @kim.pepper.

  • πŸ‡¬πŸ‡§United Kingdom catch

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

    • catch β†’ committed 9e377871 on 10.3.x
      Issue #2838474 by kim.pepper, rpayanm, alexpott, longwave, Spokje,...
  • Status changed to Fixed 9 months ago
    • catch β†’ committed 84fcf292 on 11.x
      Issue #2838474 by kim.pepper, rpayanm, alexpott, longwave, Spokje,...
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    By the way, I noticed that at least one contrib file system decorator (s3fs) still has a dependency on logger. And logging seems even more useful/necessary for s3fs than the default local file_system (all kinds of API errors, network errors, etc.). So I still see some utility in the alternative work-around of a lazy config service that loggers could depend on ( πŸ› Dependency on config storage causes circular reference in service container Needs review )

Production build 0.71.5 2024