sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Logger in CRUDController is not in container #5721

Closed petrw1 closed 3 years ago

petrw1 commented 4 years ago

Hi, I want to log errors in Sonata admin. But logger is always used NullLogger. In my project, I use monolog logger and it is accessible from container. But in Sonata Admin it is not in the container. Do I need to set it explicitly for Sonata or there is some bug?

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
# sonata-project/admin-bundle              3.54.1 3.54.1 The missing Symfony Admin Generator
sonata-project/block-bundle              3.18.1 3.18.1 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.17.0 3.17.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0  3.0.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.3.1  1.3.1  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.10.0 3.10.0 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  2.0.1  2.0.1  Lightweight Exporter library
sonata-project/formatter-bundle          4.1.3  4.1.3  Symfony SonataFormatterBundle
sonata-project/media-bundle              3.21.0 3.21.0 Symfony SonataMediaBundle
sonata-project/user-bundle               4.5.0  4.5.0  Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'
# symfony/mime                       v4.3.5             v4.3.5             A library to manipulate MIME messages
symfony/monolog-bridge             v4.3.5             v4.3.5             Symfony Monolog Bridge
symfony/monolog-bundle             v3.4.0             v3.4.0             Symfony MonologBundle
symfony/options-resolver           v4.3.5             v4.3.5             Symfony OptionsResolver Component
symfony/orm-pack                   v1.0.7             v1.0.7             A pack for the Doctrine ORM
symfony/polyfill-ctype             v1.12.0            v1.12.0            Symfony polyfill for ctype functions
symfony/polyfill-iconv             v1.12.0            v1.12.0            Symfony polyfill for the Iconv extension
symfony/polyfill-intl-icu          v1.12.0            v1.12.0            Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.12.0            v1.12.0            Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-mbstring          v1.12.0            v1.12.0            Symfony polyfill for the Mbstring extension
symfony/polyfill-php72             v1.12.0            v1.12.0            Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.12.0            v1.12.0            Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/process                    v4.3.5             v4.3.5             Symfony Process Component
symfony/profiler-pack              v1.0.4             v1.0.4             A pack for the Symfony web profiler
symfony/property-access            v4.3.5             v4.3.5             Symfony PropertyAccess Component
symfony/routing                    v4.3.5             v4.3.5             Symfony Routing Component
symfony/security-acl               v3.0.2             v3.0.2             Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.3.5             v4.3.5             Symfony SecurityBundle
symfony/security-core              v4.3.5             v4.3.5             Symfony Security Component - Core Library
symfony/security-csrf              v4.3.5             v4.3.5             Symfony Security Component - CSRF Library
symfony/security-guard             v4.3.5             v4.3.5             Symfony Security Component - Guard
symfony/security-http              v4.3.5             v4.3.5             Symfony Security Component - HTTP Integration
symfony/service-contracts          v1.1.7             v1.1.7             Generic abstractions related to writing services
symfony/stopwatch                  v4.3.5             v4.3.5             Symfony Stopwatch Component
symfony/swiftmailer-bundle         v3.3.0             v3.3.0             Symfony SwiftmailerBundle
symfony/templating                 v4.3.5             v4.3.5             Symfony Templating Component
symfony/translation                v4.3.5             v4.3.5             Symfony Translation Component
symfony/translation-contracts      v1.1.7             v1.1.7             Generic abstractions related to translation
symfony/twig-bridge                v4.3.5             v4.3.5             Symfony Twig Bridge
symfony/twig-bundle                v4.3.5             v4.3.5             Symfony TwigBundle
symfony/validator                  v4.3.5             v4.3.5             Symfony Validator Component
symfony/var-dumper                 v4.3.5             v4.3.5             Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v4.3.5             v4.3.5             A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle        v4.3.5             v4.3.5             Symfony WebProfilerBundle
symfony/web-server-bundle          v4.3.5             v4.3.5             Symfony WebServerBundle
symfony/yaml                       v4.3.5             v4.3.5             Symfony Yaml Component

PHP version

$ php -v
# PHP 7.3.9 (cli) (built: Sep  8 2019 14:56:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.9, Copyright (c) 1999-2018, by Zend Technologies

Subject

Logger is not present in container

Expected results

Logger is in container

abdielcs commented 4 years ago

Happens to me too in 4.4.3.

phansys commented 4 years ago

That's because the "logger" service is private since Symfony 3.4, and we are trying to access it from the container: https://github.com/sonata-project/SonataAdminBundle/blob/a74dcbb5b5d2bf9fd9d4cb02e86e8da52526c4bc/src/Controller/CRUDController.php#L1197-L1207

As a workaround, you could try to override the service definition in order to make it public:

services:
    logger:
        alias: 'monolog.logger'
        public: true
github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jorrit commented 3 years ago

@phansys I'm sorry to open this stale issue, but would it be an idea to leverage Psr\Log\LoggerAwareInterface in the CRUDController?