lib/bio/log/loggercli.rb in bio-logger-0.6.1 vs lib/bio/log/loggercli.rb in bio-logger-0.9.0
- old
+ new
@@ -22,31 +22,54 @@
end
end
# Parse and store trace options
def CLI::trace s
+ level = nil
sub_level = nil
+ filter = nil
opts = {}
+ # ---- split fields
a = s.split(':')
- if a.last =~ /^\d+$/
+ if a.last =~ /^=(\d+)$/
+ # ---- set exact filter
+ filter = "sub_level==#{$1}"
+ a.pop
+ elsif a.last =~ /^=/
+ # ---- set filter
+ filter = $'
+ a.pop
+ elsif a.last =~ /^\d+$/
+ # ---- the last field is the sub level
sub_level = a.pop.to_i
+ # ---- The fore-last field is the level
+ level = a.pop.downcase
+ else
+ level = a.pop.downcase
end
- level = a.pop.downcase
+ # ---- If there is another field it contains logger name(s)
+ # otherwise it is a global
outputter =
if a.size == 2
a.shift
end
if a.size == 0
- a = [:default]
+ a = [:default] # global
else
- a = a[0].split(',')
+ a = a[0].split(',') # one or more logger name(s)
end
+ # ---- update every logger
a.each do | type |
- opts[type] = { :level => level, :sub_level => sub_level }
+ opts[type] = {}
+ opts[type][:level] = level if level
+ opts[type][:sub_level] = sub_level if sub_level
+ opts[type][:filter] = filter if filter
opts[type][:outputter_name] = outputter if outputter
+ # p [type,opts[type]]
end
+ # ---- Set the globals
LoggerPlusGlobal.instance.trace ||= {}
LoggerPlusGlobal.instance.trace = LoggerPlusGlobal.instance.trace.merge(opts)
end
def CLI::configure logname = nil
@@ -57,10 +80,11 @@
trace ||= {}
default = {}
default = trace[:default] if trace[:default]
trace[logname] ||= {} if logname
trace.each do | name, opts |
+ # p [name, opts]
next if name == :default
logger_type = type
logger_type = default[:outputter_name] if default[:outputter_name]
logger_type = opts[:outputter_name] if opts[:outputter_name]
logger = LoggerPlus[name]
@@ -73,9 +97,17 @@
# p [name, logger_type]
FileOutputter.new(name, logger_type[:file])
end
set_levels(logger, default) if default
set_levels(logger, opts)
+ filter = default[:filter]
+ filter = opts[:filter] if opts[:filter]
+ if filter
+ # p filter
+ filter2 = "logger.filter { |level,sub_level,msg| #{filter} }"
+ # p filter2
+ eval(filter2)
+ end
end
end
private