Class: RestashRails::Logger

Inherits:
Object
  • Object
show all
Includes:
Logger::Severity
Defined in:
lib/restash_rails/logger.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
0.010

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configs) ⇒ Logger

Returns a new instance of Logger.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/restash_rails/logger.rb', line 9

def initialize(configs)
  self.level = configs[:level] || 'DEBUG'
  @logstash_host = configs[:host] || '127.0.0.1' #logstash host
  @logstash_port = configs[:port].to_i || 5960 #logstash port
  @app_name = configs[:app_name] || ENV['APP_NAME'] || Rails.application.class.name
  @output_type = (configs[:output_type] || 'tcp').to_s.downcase
  #TCP connection timeouts in milliseconds
  if configs[:timeout_options].present?
    configs[:timeout_options].each{ |k,v| configs[:timeout_options][k] = v.to_f }
    @timeout_options = configs[:timeout_options]
  else
    @timeout_options = { connect_timeout: DEFAULT_TIMEOUT, write_timeout: DEFAULT_TIMEOUT, read_timeout: DEFAULT_TIMEOUT }
  end
  set_formatter(configs)
  @stdout_logger = ::Logger.new(STDOUT)
  @stdout_logger.formatter = proc do |severity, datetime, progname, msg|
    "#{msg}\n"
  end
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def app_name
  @app_name
end

#formatterObject

Returns the value of attribute formatter.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def formatter
  @formatter
end

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def level
  @level
end

#logstash_hostObject

Returns the value of attribute logstash_host.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def logstash_host
  @logstash_host
end

#logstash_portObject

Returns the value of attribute logstash_port.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def logstash_port
  @logstash_port
end

#output_typeObject

Returns the value of attribute output_type.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def output_type
  @output_type
end

#outputterObject

Returns the value of attribute outputter.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def outputter
  @outputter
end

#timeout_optionsObject

Returns the value of attribute timeout_options.



6
7
8
# File 'lib/restash_rails/logger.rb', line 6

def timeout_options
  @timeout_options
end