doujiao3074
2017-08-02 08:17
浏览 65
已采纳

Graylog / Symfony2 / Gelf:如何配置记录器以忽略错误?

I'm trying to stream logs from a symfony 2 app to a graylog 2 server using the gelf format.

My monolog configuration looks as follows:

monolog:
    handlers:
          # --- 8< ---
          # ...
          # --- >8 --- 
          graylog:
              type: gelf
              publisher:
                  hostname: my-graylog-server.com
                  port: 12201
              level: debug
              formatter: app.gelf_formatter

When the graylog server is not available, I get (understandably) a connection refused error

[2017-07-28 16:03:25] app.ERROR: Failed to write to socket: fwrite(): send of 153 bytes failed with errno=111 Connection refused (8) [] []

which results in an internal server error (500 response code to the request causing the log).

(See also this question: Prevent Internal Server Error with Symfony 2 / Monolog on failed gelf connection)

gelf-php provides an IngoreErrorTransportLogger, which seems to be build for this exact purpose.

How can I configure this in Symfony's monolog config?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用gelf格式将日志从symfony 2应用程序流式传输到graylog 2服务器。

我的monolog配置如下所示:

  monolog:
处理程序:
#--- 8&lt;  --- 
#... 
#---&gt; 8 --- 
 graylog:
 type:gelf 
 publisher:
 hostname:my-graylog-server.com 
 port:12201  
 level:debug 
 formatter:app.gelf_formatter 
   
 
 

当graylog服务器不可用时,我得到(可以理解)连接拒绝错误

  [2017-07-28 16:03:25] app.ERROR:无法写入套接字:fwrite():153字节的发送失败,错误为errno = 111拒绝连接(8)  [] [] 
   
 
 

导致内部服务器错误(导致日志的请求的响应代码为500)。

(另请参阅此问题:在失败的gelf连接上防止Symfony 2 / Monolog发生内部服务器错误

gelf-php提供 IngoreErrorTransportLogger ,似乎是为了这个目的而构建的。< / p>

如何在Symfony的monolog配置中配置它?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题