<bdo id='qQNbr'></bdo><ul id='qQNbr'></ul>
<legend id='qQNbr'><style id='qQNbr'><dir id='qQNbr'><q id='qQNbr'></q></dir></style></legend>

<small id='qQNbr'></small><noframes id='qQNbr'>

    <i id='qQNbr'><tr id='qQNbr'><dt id='qQNbr'><q id='qQNbr'><span id='qQNbr'><b id='qQNbr'><form id='qQNbr'><ins id='qQNbr'></ins><ul id='qQNbr'></ul><sub id='qQNbr'></sub></form><legend id='qQNbr'></legend><bdo id='qQNbr'><pre id='qQNbr'><center id='qQNbr'></center></pre></bdo></b><th id='qQNbr'></th></span></q></dt></tr></i><div id='qQNbr'><tfoot id='qQNbr'></tfoot><dl id='qQNbr'><fieldset id='qQNbr'></fieldset></dl></div>

      <tfoot id='qQNbr'></tfoot>

      Symfony 记录到 Docker 容器内的标准输出

      Symfony logs to stdout inside Docker container(Symfony 记录到 Docker 容器内的标准输出)

      <small id='zGELx'></small><noframes id='zGELx'>

      <tfoot id='zGELx'></tfoot>

        <i id='zGELx'><tr id='zGELx'><dt id='zGELx'><q id='zGELx'><span id='zGELx'><b id='zGELx'><form id='zGELx'><ins id='zGELx'></ins><ul id='zGELx'></ul><sub id='zGELx'></sub></form><legend id='zGELx'></legend><bdo id='zGELx'><pre id='zGELx'><center id='zGELx'></center></pre></bdo></b><th id='zGELx'></th></span></q></dt></tr></i><div id='zGELx'><tfoot id='zGELx'></tfoot><dl id='zGELx'><fieldset id='zGELx'></fieldset></dl></div>

              <tbody id='zGELx'></tbody>
            • <bdo id='zGELx'></bdo><ul id='zGELx'></ul>

                <legend id='zGELx'><style id='zGELx'><dir id='zGELx'><q id='zGELx'></q></dir></style></legend>
                本文介绍了Symfony 记录到 Docker 容器内的标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在为 Symfony 应用程序构建一个 docker 映像.在这张图片中,我想将 Symfony 日志流式传输到标准输出.因此,与配置 nginx 日志的方式类似,我在 Dockerfile 中添加了这一行:

                I'm building a docker image for a Symfony application. In this image, I want to stream the Symfony logs to stdout. So, similar to how nginx logs are configured, I added this line to my Dockerfile:

                ln -sf /dev/stdout /var/www/project/app/logs/prod.log
                

                在容器内,我可以看到:

                Inside the container, I can see this:

                $ ls /var/www/project/app/logs/ -l
                total 12
                -rw-r--r-- 1 501 games 4473 Jul 21 08:36 dev.log
                lrwxrwxrwx 1 501 games   11 Jul 21 08:35 prod.log -> /dev/stdout
                

                但是,应用程序抛出以下错误:

                However, the app throws following error:

                PHP 致命错误:未捕获的异常 'UnexpectedValueException' 带有消息无法打开流或文件/var/www/project/app/logs/prod.log":无法打开流:没有这样的文件或目录' 在/var/www/project/app/cache/prod/classes.php:5808
                堆栈跟踪:
                #0/var/www/project/app/cache/prod/classes.php(5746): MonologHandlerStreamHandler->write(Array)
                #1/var/www/project/app/cache/prod/classes.php(5917): MonologHandlerAbstractProcessingHandler->handle(Array)
                #2/var/www/project/app/cache/prod/classes.php(6207): MonologHandlerFingersCrossedHandler->handle(Array)
                #3/var/www/project/app/cache/prod/classes.php(6276): MonologLogger->addRecord(500, 'Fatal Error: Un...', Array)
                #4/var/www/project/app/cache/prod/classes.php(1978): MonologLogger->log('critical', 'Fatal Error: Un...', Array)
                #5/var/www/project/app/cache/prod/classes.php(2034): SymfonyComponentDebugErrorHandler->handleException(对象(SymfonyComponentDebugExceptionFatalErrorException), Array)
                #6 [内部函数]: SymfonyComponentDebugE in/var/www/project/app/cache/prod/classes.php on line 5808

                PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/project/app/logs/prod.log" could not be opened: failed to open stream: No such file or directory' in /var/www/project/app/cache/prod/classes.php:5808
                Stack trace:
                #0 /var/www/project/app/cache/prod/classes.php(5746): MonologHandlerStreamHandler->write(Array)
                #1 /var/www/project/app/cache/prod/classes.php(5917): MonologHandlerAbstractProcessingHandler->handle(Array)
                #2 /var/www/project/app/cache/prod/classes.php(6207): MonologHandlerFingersCrossedHandler->handle(Array)
                #3 /var/www/project/app/cache/prod/classes.php(6276): MonologLogger->addRecord(500, 'Fatal Error: Un...', Array)
                #4 /var/www/project/app/cache/prod/classes.php(1978): MonologLogger->log('critical', 'Fatal Error: Un...', Array)
                #5 /var/www/project/app/cache/prod/classes.php(2034): SymfonyComponentDebugErrorHandler->handleException(Object(SymfonyComponentDebugExceptionFatalErrorException), Array)
                #6 [internal function]: SymfonyComponentDebugE in /var/www/project/app/cache/prod/classes.php on line 5808

                有什么建议吗?

                推荐答案

                借助Monolog,很容易将日志发送到stdout/stderr.我的例子是使用stderr,但我认为stdout是一样的.

                With the help of Monolog, it is very easy to send logs to stdout/stderr. My examples are using stderr, but I think it's the same with stdout.

                您只需输入首选流路径,而不是定义日志文件

                Instead of defining a log file you just enter the preferred stream path

                path:  "php://stderr"
                

                但是你还没有完成.您还必须相应地配置 PHP.工作人员必须捕获其进程的输出并将此输出再次记录到他们的标准错误中.

                BUT you are not done yet. You also have to configure PHP accordingly. The workers have to catch the output of their processes and log this output again to their stderr.

                PHP 配置

                #/etc/php/7.0/fpm/php-fpm.conf
                error_log = /proc/self/fd/2
                
                #/etc/php/7.0/fpm/pool.d/www.conf
                catch_workers_output = yes
                

                Symfony 配置

                # app/config/config_prod.yml
                monolog:
                    handlers:
                        main:
                            type:         fingers_crossed
                            action_level: error
                            handler:      nested
                        nested:
                            type:  stream
                            path:  "php://stderr"
                            level: debug
                        console:
                            type:  console
                

                如果您在胖 docker 容器中使用任何过程控制系统,则必须确保该系统也记录到 stdout(或 stderr).

                If you are using any process control system in a fat docker container you have to make sure that this system also logs to stdout (or stderr).

                以主管为例:

                [supervisord]
                nodaemon=true
                ;@see http://blog.turret.io/basic-supervisor-logging-with-docker/
                ;we need the output from the controlled processes
                ;but this is only possible with lowered loglevel
                loglevel=debug
                

                总而言之,请确保:

                • 应用程序记录到 stdout/stderr
                • PHP 捕获 worker 输出并记录到 stderr
                • 可选:任何流程控制系统都必须将托管流程的输出转发到 stdout/stderr

                这篇关于Symfony 记录到 Docker 容器内的标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How do I parse XML containing custom namespaces using SimpleXML?(如何使用 SimpleXML 解析包含自定义命名空间的 XML?)
                SimpleXML SOAP response Namespace issues(SimpleXML SOAP 响应命名空间问题)
                Problems with PHP namespaces and built-in classes, how to fix?(PHP 命名空间和内置类的问题,如何解决?)
                Use php namespace inside function(在函数内部使用 php 命名空间)
                unexpected #39;use#39; (T_USE) when trying to use composer(尝试使用作曲家时意外的“使用(T_USE))
                PHP adding custom namespace using autoloader from composer(PHP使用来自作曲家的自动加载器添加自定义命名空间)
                    <i id='tig6i'><tr id='tig6i'><dt id='tig6i'><q id='tig6i'><span id='tig6i'><b id='tig6i'><form id='tig6i'><ins id='tig6i'></ins><ul id='tig6i'></ul><sub id='tig6i'></sub></form><legend id='tig6i'></legend><bdo id='tig6i'><pre id='tig6i'><center id='tig6i'></center></pre></bdo></b><th id='tig6i'></th></span></q></dt></tr></i><div id='tig6i'><tfoot id='tig6i'></tfoot><dl id='tig6i'><fieldset id='tig6i'></fieldset></dl></div>

                    <small id='tig6i'></small><noframes id='tig6i'>

                    • <bdo id='tig6i'></bdo><ul id='tig6i'></ul>

                      <tfoot id='tig6i'></tfoot>
                        <legend id='tig6i'><style id='tig6i'><dir id='tig6i'><q id='tig6i'></q></dir></style></legend>
                          <tbody id='tig6i'></tbody>