<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 容器内的标准输出

      时间:2024-05-11

      <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 容器内的标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Docker:在 Windows 上使用 Docker Toolbox 共享卷 下一篇:Docker-php-ext-install mcrypt 缺少文件夹

                相关文章

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