Sha256: a619b3e774edb77bb948bf814c87e827462a18e065156c76b70ea6b281998e01

Contents?: true

Size: 682 Bytes

Versions: 3

Compression:

Stored size: 682 Bytes

Contents

class CustomFormatter
  def call(severity, datetime, _, data)
    res = {
        severity: severity,
        type: data.class == String ? "query" : "response",
        date: datetime,
        data: data.class == String ? data : JSON.parse(data.to_json)
    }

    application = Application.find_by(code: ENV['LOG_APP_CODE'])
    unless application.nil?
      application.application_logs.create(res)
    end
    "#{res.to_json}\n"
  end
end

Rails.application.configure do
  $log_file = File.open("log/#{ENV['RAILS_ENV']}.log", 'a')
  $log_file.sync = true

  ActiveRecord::Base.logger = Logger.new(GrapeLogging::MultiIO.new($log_file, STDERR), formatter: CustomFormatter.new)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
log_ranger-0.1.7 lib/log_ranger/log_ranger/templates/config/initializers/log_ranger.rb
log_ranger-0.1.6 lib/log_ranger/log_ranger/templates/config/initializers/log_ranger.rb
log_ranger-0.1.5 lib/log_ranger/log_ranger/templates/config/initializers/log_ranger.rb