Fluentd:无法将Rails日志管道传输到Fluentd STDOUT



我将根据Fluentd的这篇文章来设置Fluentd与Rails的工作版本。我的fluent-logger.yml:

development:
  fluent_host: "localhost"
  fluent_port: 24224
  tag: "foo"
  messages_type: "string"

application.rb:

config.log_level = :info
config.logger = ActFluentLoggerRails::Logger.new
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new

我的td-agent.conf指令如下:

<source>
  type forward
  port 24224
</source>
<match foo>
  type stdout
</match>

当我启动rails服务器时,我没有看到任何日志消息通过管道传输到td-agent.log。我使用的是act fluent logger rails gem。

然而,当我在rails控制台中使用fluent logger gem并执行以下命令时:

require 'fluent-logger'
Fluent::Logger::FluentLogger.open(nil, :host=>'localhost',:port=>24224)
Fluent::Logger.post("fluentd.test.follow",{"from"=>"A","to"=>"B"})

我可以看到STDOUT中填充了我发送的消息。在应用程序中运行它,我哪里出了问题?任何人都会注意到这一点!TIA。

也许您的Rails应用程序是一个API。在这种情况下,您可能必须设置config.lograge.base_controller_class = 'ActionController::API'

最新更新