Module: Alog
- Defined in:
- lib/alog.rb,
lib/alog/version.rb
Defined Under Namespace
Classes: AOlogger, AlogException, Alogger
Constant Summary collapse
- LogTag =
allow application to provide which tag should print out
[:global]
- LogFacts =
allow application to configure multiple logging log factories configurations
{}
- GLog =
multi logger created from LogFacts entry given by application
{}
- CondLog =
Actual logic of detecting a tag should be activated and on which logger should it written to
Proc.new do |msg, params = {}, &block| key = params[:key] || :global type = params[:type] || :debug if defined?(:LogTag) and LogTag.is_a?(Array) and (LogTag.include?(key) or LogTag.include?(:all)) or type == :error logEng = params[:logEng] if logEng == nil or (logEng != nil and logEng.empty?) logEng = (LogFacts.length > 0 ? [LogFacts.keys[0]] : [:default]) end logEng = [logEng] if not logEng.is_a?(Array) # allow written to multiple logger logEng.each do |e| if GLog[e] == nil lp = LogFacts[e] if lp == nil # default if empty lp = [STDOUT] end # ensure the same configuration only created a logger object once GLog[e] = Alogger.new(lp) end GLog[e].log("#{caller.length > 3 ? "[#{File.basename(caller[4])}]" : ""} [#{key}] #{msg}", type, &block) end end end
- VERSION =
"0.2.0"
Instance Method Summary collapse
-
#clog(msg, ltype = :debug, key = :global, logEng = []) ⇒ Object
Module level clog() method Meant to be called by application INSIDE the l()‘s block.
-
#l(key = :global, params = { type: :debug, logEng: [] }, &block) ⇒ Object
Provide a block construct that can set values consistantly for multiple clog() call TODO How to make this thread safe?.
-
#log(msg, params = { }, &block) ⇒ Object
provide module level method to write to the logger object.
- #selected_tags_only ⇒ Object
-
#show_all_tags ⇒ Object
end class AloggerObject.
Instance Method Details
#clog(msg, ltype = :debug, key = :global, logEng = []) ⇒ Object
Module level clog() method Meant to be called by application INSIDE the l()‘s block
113 114 115 116 117 |
# File 'lib/alog.rb', line 113 def clog(msg, ltype = :debug, key = :global, logEng = []) log(msg, { type: @lType != ltype ? ltype : @lType, key: (key == @lKey ? key : @lKey), logEng: @llEng }) end |
#l(key = :global, params = { type: :debug, logEng: [] }, &block) ⇒ Object
Provide a block construct that can set values consistantly for multiple clog() call TODO How to make this thread safe?
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/alog.rb', line 95 def l(key = :global, params = { type: :debug, logEng: [] } ,&block) # this construct try to make the variable private to the block # Still not sure will error condition exist for multi threaded application b = Proc.new do |key, params, &block| @lKey = key @lType = params[:type] @llEng = params[:logEng] if block block.call end end b.call(key, params, &block) end |
#log(msg, params = { }, &block) ⇒ Object
provide module level method to write to the logger object
162 163 164 |
# File 'lib/alog.rb', line 162 def log(msg, params = { }, &block) CondLog.call(msg, params, &block) end |
#selected_tags_only ⇒ Object
87 88 89 |
# File 'lib/alog.rb', line 87 def LogTag.delete(:all) end |
#show_all_tags ⇒ Object
end class AloggerObject
83 84 85 |
# File 'lib/alog.rb', line 83 def LogTag << :all end |