Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么symfony 2.7不记录控制器的通知_Php_Symfony - Fatal编程技术网

Php 为什么symfony 2.7不记录控制器的通知

Php 为什么symfony 2.7不记录控制器的通知,php,symfony,Php,Symfony,我有以下行动: public function getQuestions2Action() { MY_CONSTANT; } app/config/config_prod.yml imports: - { resource: config.yml } monolog: handlers: main: type: stream path: "%kernel.logs_dir%/%kernel.env

我有以下行动:

public function getQuestions2Action()
{
    MY_CONSTANT;
}
app/config/config_prod.yml

imports:
    - { resource: config.yml }

monolog:
    handlers:
        main:
            type:   stream
            path:   "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            channels: "!event"
在/var/log/nginx/error.log中,我看到:

2016/01/21 14:39:48 [error] 31596#0: *313 FastCGI sent in stderr: "PHP message: PHP Notice:  Use of undefined constant MY_CONSTANT - assumed 'MY_CONSTANT' in /var/www/datravel-client-api/src/Datravel/ClientApiBundle/Controller/RestController.php on line 289
PHP message: PHP Stack trace:
PHP message: PHP   1. {main}() /var/www/datravel-client-api/web/app.php:0
PHP message: PHP   2. Symfony\Component\HttpKernel\Kernel->handle($request = *uninitialized*, $type = *uninitialized*, $catch = *uninitialized*) /var/www/datravel-client-api/web/app.php:27
PHP message: PHP   3. Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle($request = *uninitialized*, $type = *uninitialized*, $catch = *uninitialized*) /var/www/datravel-client-api/app/bootstrap.php.cache:2442
PHP message: PHP   4. Symfony\Component\HttpKernel\HttpKernel->handle($request = *uninitialized*, $type = *uninitialized*, $catch = *uninitialized*) /var/www/datravel-client-api/app/bootstrap.php.cache:3223
PHP message: PHP   5. Symfony\Component\HttpKernel\HttpKernel->handleRaw($request = *uninitialized*, $type = *uninitialized*) /var/www/datravel-client-api/app/bootstrap.php.cache:3072
PHP message: PHP   6. call_user_func_array:{/var/www/datravel-client-api/app/bootstrap.php.cache:3110}(*uninitialized*, *uninitialized*) /var/www/datravel-client-api/app/bootstrap.php.cache:3110
PHP message: PHP   7. Datravel\ClientApiBundle\Controller\RestController->getQuestions2Action() /var/www/datravel-client-api/app/bootstrap.php.cache:3110" while reading response header from upstream, client: 127.0.0.1, server: datravel-client-api.local, request: "GET /api/v1/client/questions2.json HTTP/1.1", upstream: "fastcgi://127.0.0.1:9400", host: "datravel-client-api.local"
但是app/logs/prod.log是空的

$ ls -la app/logs/
total 8
drwxrwxrwx 2 lebnik lebnik 4096 дек.  18 14:02 .
drwxrwxr-x 6 lebnik lebnik 4096 янв.  21 12:59 ..
-rw-rw-r-- 1 lebnik lebnik    0 июля  31 17:20 .gitkeep
-rwxrwxrwx 1 lebnik lebnik    0 дек.  18 14:02 prod.log
Prod缓存已清除。我期待关于未定义常量的日志记录通知

$php5 fpm-v

PHP 5.6.11-1ubuntu3.1 (fpm-fcgi)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

您在/var/log/nginx/error.log中得到错误,表示未定义MY_常量。 我不知道您在代码中的何处定义了它(可能是在超类或您包含的其他类中?),但我认为您无法获得除“您尚未定义它”之外的任何信息,除非PHP解析器无法在适当的位置找到它。 也许你可以搜索你的项目,找到你在哪里定义这个“MY_常量”,格式如下
const MY_CONSTANT=xxx

与应用程序在“调试模式”下运行的
dev
环境不同(这意味着
error_reporting
由symfony自身设置为
E_ALL
,所有错误都转换为异常并记录),在
prod
环境中
错误报告
是您在
php.ini
中设置的内容,php错误不由symfony处理。但是,PHP将它们记录在中指定的文件中,通常是
/var/log/httpd/error\u log
/var/log/apache2/error.log

如果您想在生产中处理php错误,并通过monolog记录这些错误,可以注册
Symfony\Component\HttpKernel\EventListener\DebugHandlersListener
listener。为您服务:

 debug.debug_handlers_listener:
     class: Symfony\Component\HttpKernel\EventListener\DebugHandlersListener
     arguments: [~, "@logger", 24575, ~, false]
     tags:
         -  { name: kernel.event_subscriber}
24575
E_ALL^E_DEPRECATED
的输出

更新 我认为,由于这两种环境中的
debug.debug\u handlers\u listener
,您应该创建如下编译器过程:

namespace TestBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class DebugHandlersCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->getParameter('kernel.debug')) {
            $definition = $container->findDefinition('debug.debug_handlers_listener');

            // by default is E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR
            $definition->replaceArgument(2, E_ALL ^ E_DEPRECATED);
            $definition->replaceArgument(4, false);
        }
    }
}
namespace TestBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use TestBundle\DependencyInjection\Compiler\DebugHandlersCompilerPass;

class TestBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        // add this
        $container->addCompilerPass(new DebugHandlersCompilerPass());
    }
}
然后像这样注册它:

namespace TestBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class DebugHandlersCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->getParameter('kernel.debug')) {
            $definition = $container->findDefinition('debug.debug_handlers_listener');

            // by default is E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR
            $definition->replaceArgument(2, E_ALL ^ E_DEPRECATED);
            $definition->replaceArgument(4, false);
        }
    }
}
namespace TestBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use TestBundle\DependencyInjection\Compiler\DebugHandlersCompilerPass;

class TestBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        // add this
        $container->addCompilerPass(new DebugHandlersCompilerPass());
    }
}

您现在需要做的就是将
config\u prod.yml
文件中
monolog
action\u level:error
更改为
action\u level:warning

从明显的开始-您清除了产品缓存了吗?您希望在日志中看到什么-您正在记录自定义通知吗?1。prod缓存已清除2。是的,请输入您试图记录的通知的代码-即从控制器复制和粘贴。没问题,一切就绪。我看到prod.log的所有者是“lebnik lebnik”。你试过检查权限是否有问题吗?我说不出来,我已经搜索过了,但什么也没找到。我甚至不认为在生产中这样做是个好主意。。只需查看您的
错误日志
文件即可。