Module: Airfoil

Defined in:
lib/airfoil.rb,
lib/airfoil/railtie.rb,
lib/airfoil/version.rb,
lib/airfoil/middleware/base.rb,
lib/airfoil/cloudwatch_formatter.rb,
lib/airfoil/middleware/log_event.rb,
lib/airfoil/middleware/function_name.rb,
lib/airfoil/middleware/logger_tagging.rb,
lib/airfoil/middleware/set_request_id.rb

Defined Under Namespace

Modules: Middleware Classes: CloudwatchFormatter, Railtie

Constant Summary collapse

VERSION =
'0.1.6'

Class Method Summary collapse

Class Method Details

.create_stack(logger) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/airfoil.rb', line 15

def create_stack(logger)
  # ensure that STDOUT streams are synchronous so we don't lose logs
  $stdout.sync = true

  Signal.trap("TERM") do
    # We can't use the Rails logger here as the logger is not available in the trap context
    puts "Received SIGTERM, shutting down gracefully..."
  end

  logger ||= defined?(::Rails) ? Rails.logger : Logger.new($stdout, level: (ENV["LOG_LEVEL"] || :info).to_sym)

  ::Middleware::Builder.new { |b|
    if defined?(::Rails)
      b.use Middleware::LoggerTagging, logger
    end
    b.use Middleware::SetRequestId
    # This is causing infinite recursion for some reason
    # b.use Middleware::LogEvent, logger
    yield b
  }.inject_logger(logger)
end