class Alog::AOlogger

class AloggerObject Mimiking the original Logger object to be used by application but with the conditioning logging logic available to the application instead

Attributes

logEng[R]

Public Class Methods

new(params = { key: :global, logEng: [], active_tag: LogTag } ) click to toggle source
Major change on v1.0

def initialize(key = :global, logEng = [], active_tag = LogTag)

# File lib/alog.rb, line 54
def initialize(params = { key: :global, logEng: [], active_tag: LogTag } )
  @myMethods = [:debug, :error, :warn, :warning, :info]
  @defKey = params[:key]
  @logEng = params[:logEng] || []
  @activeTag = params[:active_tag] || []
end

Public Instance Methods

activate_tag(tag, &block) click to toggle source
# File lib/alog.rb, line 65
def activate_tag(tag, &block)
  @activeTag << tag
  if block
    block.call 
    @activeTag.delete(tag)
  end
end
deactivate_tag(tag) click to toggle source
# File lib/alog.rb, line 73
def deactivate_tag(tag)
  @activeTag.delete(tag)
end
ext_error(ex) click to toggle source
# File lib/alog.rb, line 77
def ext_error(ex)
  if ex.is_a?(Exception)
    error(ex.message)
    error(ex.backtrace.join("\n"))
  else
    error(ex)
  end
end
log(msg, ltype = :debug, key = :global, logEng = [], active_tag = []) click to toggle source
# File lib/alog.rb, line 61
def log(msg, ltype = :debug, key = :global, logEng = [], active_tag = [])
  CondLog.call(msg, { key: (key == :global ? key : @defKey), type: ltype, logEng: (logEng == [] ? @logEng : logEng), active_tag: (active_tag == [] ? @activeTag : active_tag) })
end
method_missing(mtd, *args, &block) click to toggle source
Calls superclass method
# File lib/alog.rb, line 98
def method_missing(mtd, *args, &block)
  if @myMethods.include?(mtd)
    params = {}
    pa = args[1]
    params[:key] = @defKey
    params[:logEng] = @logEng
    params[:active_tag] = @activeTag
    # TODO cases here may not be extensive to
    # the original Logger supported.
    case mtd
    when :debug
      params[:type] = :debug
      CondLog.call(args[0], params, &block)
    when :error
      params[:type] = :error
      CondLog.call(args[0], params, &block)
    when :warn, :warning
      params[:type] = :warn
      CondLog.call(args[0], params, &block)
    when :info
      params[:type] = :info
      CondLog.call(args[0], params, &block)
    end
    
  else
    super
  end
end
no_active_tags() click to toggle source
# File lib/alog.rb, line 86
def no_active_tags
  @activeTag = []
end
selected_tags_only() click to toggle source
# File lib/alog.rb, line 94
def selected_tags_only
  @activeTag.delete(:all)
end
show_all_tags() click to toggle source
# File lib/alog.rb, line 90
def show_all_tags
  @activeTag << :all
end