Skip to content

Instantly share code, notes, and snippets.

@renatodex
Last active November 11, 2022 23:10
Show Gist options
  • Save renatodex/d666b2531298baff18c3f0a171b04be2 to your computer and use it in GitHub Desktop.
Save renatodex/d666b2531298baff18c3f0a171b04be2 to your computer and use it in GitHub Desktop.
Debug Log
require 'singleton'
class DebugLog < Logger
include Singleton
def initialize(log_file = 'debug')
super(Rails.root.join("log/#{log_file}.log"))
self.formatter = formatter()
self
end
# Optional, but good for prefixing timestamps automatically
def formatter
Proc.new{|severity, time, progname, msg|
formatted_severity = sprintf("%-5s",severity.to_s)
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S")
"[#{formatted_severity} #{formatted_time} #{$$}] #{msg.to_s.strip}\n"
}
end
class << self
delegate :error, :debug, :fatal, :info, :warn, :add, :log, :to => :instance
def p(msg)
self.info(JSON.pretty_generate(msg))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment