Class: Xlog::Xlogger
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#app_root ⇒ Object
Returns the value of attribute app_root.
-
#base_logger ⇒ Object
Returns the value of attribute base_logger.
Instance Method Summary collapse
- #and_raise_error(e, message, data, tags) ⇒ Object
- #custom_logger=(logger) ⇒ Object
-
#error(e, message, data, tags) ⇒ Object
do NOT refactor error and and_raise_error.
- #info(message, data, tags) ⇒ Object
-
#initialize ⇒ Xlogger
constructor
A new instance of Xlogger.
- #log(type, text, tags) ⇒ Object
- #warn(message, data, tags) ⇒ Object
Constructor Details
#initialize ⇒ Xlogger
9 10 11 12 13 14 15 |
# File 'lib/xlog/xlogger.rb', line 9 def initialize @base_logger = ActiveSupport::TaggedLogging.new(Logger.new("log/xlog_#{Rails.env}.log", 'weekly')) @app_name = Rails.application.class.to_s.split('::')[0].underscore @app_root = Rails.root.to_s @folder_names_to_remove = Dir.glob('app/*').map { |f| f.gsub('app/', '') } end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
7 8 9 |
# File 'lib/xlog/xlogger.rb', line 7 def app_name @app_name end |
#app_root ⇒ Object
Returns the value of attribute app_root.
7 8 9 |
# File 'lib/xlog/xlogger.rb', line 7 def app_root @app_root end |
#base_logger ⇒ Object
Returns the value of attribute base_logger.
7 8 9 |
# File 'lib/xlog/xlogger.rb', line 7 def base_logger @base_logger end |
Instance Method Details
#and_raise_error(e, message, data, tags) ⇒ Object
36 37 38 39 |
# File 'lib/xlog/xlogger.rb', line 36 def and_raise_error(e, , data, ) log(:error, "#{e.class}: #{e.try(:message)}. #{newline} #{compose_log(message, data)} #{newline} Error backtrace: #{newline} #{backtrace(e)}", ) .present? ? raise(e, ) : raise(e) end |
#custom_logger=(logger) ⇒ Object
41 42 43 |
# File 'lib/xlog/xlogger.rb', line 41 def custom_logger=(logger) @base_logger = ActiveSupport::TaggedLogging.new(logger) end |
#error(e, message, data, tags) ⇒ Object
do NOT refactor error and and_raise_error
31 32 33 34 |
# File 'lib/xlog/xlogger.rb', line 31 def error(e, , data, ) # they MUST BE NOT DRY in order to log correct backtrace log(:error, "#{e.class}: #{e.try(:message)}. \n #{compose_log(message, data)} \n Error backtrace: \n#{backtrace(e)}", ) end |
#info(message, data, tags) ⇒ Object
22 23 24 |
# File 'lib/xlog/xlogger.rb', line 22 def info(, data, ) log(:info, compose_log(, data), ) end |
#log(type, text, tags) ⇒ Object
17 18 19 20 |
# File 'lib/xlog/xlogger.rb', line 17 def log(type, text, ) = [time_stamp, called_from(type), type] + Array.wrap() @base_logger.tagged(.compact) { @base_logger.send(type, text) } end |
#warn(message, data, tags) ⇒ Object
26 27 28 |
# File 'lib/xlog/xlogger.rb', line 26 def warn(, data, ) log(:warn, compose_log(, data), ) end |