dwbutler / logstash-logger

Ruby logger that writes logstash events
MIT License
456 stars 118 forks source link

Messages not sending while using rails runner #91

Closed kenanokeefe closed 8 years ago

kenanokeefe commented 8 years ago

Hello,

The simple method below sends the message while in rails console, but does not send while using rails runner.

  def logstash_test
    logger = LogStashLogger.new(type: :tcp, host: 'localhost', port: 5231, error_logger: Logger.new(STDOUT))
    logger.info(test:Time.now)
    p logger
  end

When printing the logger instance via rails runner, its seems that the message is pending:

@buffer_state={:pending_items=>{nil=>["{\"test\":\"2016-08-09T12:58:43.879-04:00\",\"@timestamp\":\"2016-08-09T12:58:43.879-04:00\",\"@version\":\"1\",\"severity\":\"INFO\",\"host\":\"localhost\"}\n"]}`...

This may simply be an issue with rails runner / spring, but thought i'd post it here. Thx!

dwbutler commented 8 years ago

Hi,

Thanks for the report. What's going on here is that your logger is buffering incoming messages. By default, messages are flushed every five seconds. If you exit the program before the flush happens, the buffer is lost. You can reproduce this in the rails console by exiting immediately after calling that method.

This is fixed in #92

dwbutler commented 8 years ago

The fix has been released in 0.19.0.

kenanokeefe commented 8 years ago

Awesome, thx for the response!