Created
February 25, 2022 15:39
-
-
Save katpadi/bf85420f989bde7c42e0213de382636f to your computer and use it in GitHub Desktop.
Jotter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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