SHARE
TWEET

Untitled

a guest Oct 15th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module CustomLogger
  2.   class << self
  3.     def new(attrs = {})
  4.       ::Logger.new(device).tap do |logger|
  5.         logger.instance_variable_set(:@device, device)
  6.         logger.instance_variable_set(:@log_type, attrs.fetch(:log_type, :trace))
  7.         logger.extend(self)
  8.       end
  9.     end
  10.  
  11.     def device
  12.       @device ||= (Settings.custom_logger.type == 'file' ? Device::File : Device::Logstash).new
  13.     end
  14.   end
  15.  
  16.   attr_reader :log_type
  17.  
  18.   def add(severity, message = nil, progname = nil, &block)
  19.     super if progname.present? && progname.is_a?(Hash) || block_given? && yield.is_a?(Hash)
  20.   end
  21.  
  22.   def format_message(severity, timestamp, progname, message)
  23.     {
  24.       severity: severity,
  25.       log_type: log_type,
  26.       app_version: "some version",
  27.       country: Settings.country,
  28.       fqdn: Settings.custom_logger.fqdn,
  29.       created_at: timestamp.strftime("%FT%T%:z"),
  30.       request_ip: Thread.current[:request_ip],
  31.       iid: Thread.current[:request_id],
  32.       uuid: SecureRandom.uuid,
  33.       method: message[:method],
  34.       path: message[:path],
  35.       action: message[:action],
  36.       status: message[:status],
  37.       duration: message[:duration],
  38.       view: message[:view],
  39.       db: message[:db],
  40.       es: message[:es],
  41.       details: message.to_json
  42.     }.to_json
  43.   end
  44. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top