Module: LogjamAgent::Sinatra

Defined in:
lib/logjam_agent/sinatra.rb

Defined Under Namespace

Modules: Helpers Classes: Middleware

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



61
62
63
64
65
66
# File 'lib/logjam_agent/sinatra.rb', line 61

def self.registered(app)
  app.helpers Helpers
  LogjamAgent.environment_name = ENV['LOGJAM_ENV'] || app.settings.environment.to_s
  LogjamAgent.auto_detect_logged_exceptions
  LogjamAgent.disable! if app.settings.environment.to_sym == :test
end

Instance Method Details

#setup_logjam_loggerObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/logjam_agent/sinatra.rb', line 31

def setup_logjam_logger
  log_path = ENV["APP_LOG_TO_STDOUT"].present? ? STDOUT : "#{settings.root}/log/#{LogjamAgent.environment_name}.log"
  logger = LogjamAgent::BufferedLogger.new(log_path) rescue LogjamAgent::BufferedLogger.new(STDERR)

  loglevel = settings.respond_to?(:loglevel) ? settings.loglevel : :info
  logger.level = ::Logger.const_get(loglevel.to_s.upcase)

  LogjamAgent.log_device_log_level = logger.level
  LogjamAgent.log_device_log_level = ::Logger::ERROR unless %i[test development].include?(settings.environment.to_sym)

  logger.formatter = settings.respond_to?(:logformatter) ? settings.logformatter : Logger::Formatter.new
  logger = ActiveSupport::TaggedLogging.new(logger)
  LogjamAgent.logger = logger
  ActiveSupport::LogSubscriber.logger = logger

  log_path = ENV["APP_LOG_TO_STDOUT"].present? ? STDOUT : "#{settings.root}/log/logjam_agent_error.log"
  forwarding_error_logger = ::Logger.new(log_path) rescue ::Logger.new(STDERR)
  forwarding_error_logger.level = ::Logger::ERROR
  forwarding_error_logger.formatter = ::Logger::Formatter.new
  LogjamAgent.forwarding_error_logger = forwarding_error_logger

  truncate_overlong_params = lambda { |key, value|
    max_size = LogjamAgent.max_logged_size_for(key)
    if value.is_a?(String) && value.size > max_size
      value[max_size..-1] = " ... [TRUNCATED]"
    end
  }
  LogjamAgent.parameter_filters << truncate_overlong_params
end