Class: Alog::AOlogger

Inherits:
Object
  • Object
show all
Defined in:
lib/alog.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = { key: :global, logEng: [], active_tag: LogTag }) ⇒ AOlogger

Major change on v1.0 def initialize(key = :global, logEng = [], active_tag = LogTag)



54
55
56
57
58
59
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mtd, *args, &block) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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

Instance Attribute Details

#logEngObject (readonly)

Returns the value of attribute logEng.



51
52
53
# File 'lib/alog.rb', line 51

def logEng
  @logEng
end

Instance Method Details

#activate_tag(tag, &block) ⇒ Object



65
66
67
68
69
70
71
# 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) ⇒ Object



73
74
75
# File 'lib/alog.rb', line 73

def deactivate_tag(tag)
  @activeTag.delete(tag)
end

#ext_error(ex) ⇒ Object



77
78
79
80
81
82
83
84
# 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 = []) ⇒ Object



61
62
63
# 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

#no_active_tagsObject



86
87
88
# File 'lib/alog.rb', line 86

def no_active_tags
  @activeTag = []
end

#selected_tags_onlyObject



94
95
96
# File 'lib/alog.rb', line 94

def selected_tags_only
  @activeTag.delete(:all)
end

#show_all_tagsObject



90
91
92
# File 'lib/alog.rb', line 90

def show_all_tags
  @activeTag << :all
end