Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to send logs: special settings to add to logstash conf file ? #147

Open
belgoros opened this issue Aug 16, 2018 · 2 comments
Open

Comments

@belgoros
Copy link

belgoros commented Aug 16, 2018

Do I need to add special settings to put into the Logstash configuration file or any others to make it work ? Can firewall or proxy settings block that ?
Actually, I can see logs written only pic.log file.

I have the following gems declared in Rails API Gemfile:

ruby '2.5.0'
gem 'rails', '~> 5.2.0'
...

group :development, :pic, :staging do
  gem 'lograge',         '~> 0.10.0'
  gem 'logstash-event',  '~> 1.2'
  gem 'logstash-logger', '~> 0.26.1'
...
end

Here is the settings in config/environement/pic.rb:

...
config.lograge.enabled = true
  config.lograge.base_controller_class = 'ActionController::API'
  config.lograge.formatter = Lograge::Formatters::Logstash.new
  config.lograge.logger = LogStashLogger.new(
    type: :multi_logger,
    outputs: [
      { type: :file, path: "log/#{Rails.env}.log", formatter: ::Logger::Formatter },
      { type: :tcp, host: ENV['logstash_host'], port: ENV['logstash_port'], formatter: :json }
      ],
    verify_hostname: false
  )
      
  config.lograge.custom_options = lambda do |event|
    { name:'decastore-pic', host: event.payload[:host] }
  end

there are no logs when I tried to see it in Kibana dashboard (I hoped to filter by decastore by setting name option):
screen shot 2018-08-16 at 11 15 47

Even when trying to run the following ruby script:

require 'logstash-logger'

logger = LogStashLogger.new(
  type: :tcp,
  host: 'logstash_host_name',
  port: 3332,
  verify_hostname: false
)

logger.debug message: 'decastore-draft', foo: 'bar'
logger.info 'decastore-draft => test'

nothing is sent either.

@dwbutler
Copy link
Owner

dwbutler commented Oct 7, 2018

Have you read this note: https://github.com/dwbutler/logstash-logger#logstash-never-receives-any-logs and tried setting sync: true?

@belgoros
Copy link
Author

@dwbutler Thank you, I've tried to set sync: true in my staging.rb file:

config.log_formatter = ::Logger::Formatter.new
...
if ENV['RAILS_LOG_TO_STDOUT'].present?
    config.log_level = :info
    config.lograge.enabled = true
    config.lograge.base_controller_class = 'ActionController::API'
    config.lograge.formatter = Lograge::Formatters::Logstash.new

    config.lograge.custom_options = lambda do |event|
      exceptions = %w[controller action format id]
      {
        time: event.time,
        stack: 'decastore',
        host: event.payload[:host],
        params: event.payload[:params].except(*exceptions)
      }
    end

    config.lograge.logger = LogStashLogger.new(
      type: :tcp,
      host: ENV['logstash_host'],
      port: ENV['logstash_port'],
      verify_hostname: false,
      sync: true
    )
  end

I also tries to just run the following in rails console:

logger = LogStashLogger.new(type: :tcp, host: 'logstash-host.org', port: 3332, verify_hostname: false, sync: true)
logger.info 'decastore => test port 3332'

It fails both with udp and tcp type values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants