Skip to content

Instantly share code, notes, and snippets.

@katpadi
Created February 25, 2022 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katpadi/bf85420f989bde7c42e0213de382636f to your computer and use it in GitHub Desktop.
Save katpadi/bf85420f989bde7c42e0213de382636f to your computer and use it in GitHub Desktop.
Jotter
# frozen_string_literal: true
module Jotter
def jot_info(tag = '')
Rails.logger.tagged(facility + " #{tag}") do
Rails.logger.info { yield }
end
end
def jot_debug(tag = '')
Rails.logger.tagged(facility + " #{tag}") do
Rails.logger.debug { yield }
end
end
def jot_error(tag = '')
Rails.logger.tagged(facility + " #{tag}") do
Rails.logger.error { yield }
end
end
def jot_warn(tag = '')
Rails.logger.tagged(facility + " #{tag}") do
Rails.logger.warn { yield }
end
end
def jot_fatal(tag = '')
Rails.logger.tagged(facility + " #{tag}") do
Rails.logger.fatal { yield }
end
end
def jot_ex(exception)
"#{exception.message}\n#{pretty_backtrace(exception)}"
end
private
def pretty_backtrace(exception)
"\tat #{exception.backtrace.join("\n\tat ")}"
end
def facility
@facility ||= self.class.name.gsub(/::/, '.').gsub(/([a-z])([A-Z])/, '\\1_\\2')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment