bio-logger 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
+ gem 'log4r', '>= 1.1.9'
5
6
 
6
7
  # Add dependencies to develop your gem here.
7
8
  # Include everything needed to run rake, tests, features, etc.
@@ -10,5 +11,6 @@ group :development do
10
11
  gem "bundler", "~> 1.0.0"
11
12
  gem "jeweler", "~> 1.5.2"
12
13
  gem "rcov", ">= 0"
13
- gem "bio", ">= 1.4.1"
14
+ # gem "bio", ">= 1.4.1"
15
+ gem "rspec", ">= 2.3.0"
14
16
  end
@@ -1,22 +1,32 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- bio (1.4.1)
4
+ diff-lcs (1.1.2)
5
5
  git (1.2.5)
6
6
  jeweler (1.5.2)
7
7
  bundler (~> 1.0.0)
8
8
  git (>= 1.2.5)
9
9
  rake
10
+ log4r (1.1.9)
10
11
  rake (0.8.7)
11
12
  rcov (0.9.9)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
12
21
  shoulda (2.11.3)
13
22
 
14
23
  PLATFORMS
15
24
  ruby
16
25
 
17
26
  DEPENDENCIES
18
- bio (>= 1.4.1)
19
27
  bundler (~> 1.0.0)
20
28
  jeweler (~> 1.5.2)
29
+ log4r (>= 1.1.9)
21
30
  rcov
31
+ rspec (>= 2.3.0)
22
32
  shoulda
@@ -1,37 +1,47 @@
1
1
  = bio-logger
2
2
 
3
3
  This is a plugin for nailing down problems with big data parsers,
4
- common in bioinformatics, and sane handling of errors and exceptions in different
5
- situations (log-act). A logger can be made to behave differently as
4
+ nowadays so common in bioinformatics, and sane handling of errors and
5
+ exceptions in different situations (log-act).
6
+
7
+ For example, using bio-logger, messages can be
8
+ filtered from the program
9
+
10
+ log.filter { | level, sub_level, msg | sub_level == 3 or level <= ERROR }
11
+
12
+ or can be made to behave differently based on roles of the caller as
6
13
 
7
14
  * NormalUser
8
15
  * Developer (or FailOnError)
9
16
  * WebServer
10
17
  * FaultTolerant systems
11
18
 
12
- One example of the use of having different behaviours, is when a program logs a
13
- warning to stdout as a user, but raises an exception as a developer.
14
- In Bioinformatics this is a common scenario when dealing with parsers.
15
- Large data files sometimes contain errors. As a user you want to
16
- continue and hope for the best (logging the error). As a developer you
17
- want to see how you can fix the problem. Waiting for a full run and
18
- checking the logs is tedious. The logger can be helpful here, and
19
- avoids sticking 'temporary' solutions in code.
19
+ One example of the use of having different behaviours, is when a
20
+ program logs a warning to stdout when called as a user, but raises an
21
+ exception when called as a developer. In Bioinformatics this is a
22
+ common scenario when dealing with parsers. Large data files sometimes
23
+ contain errors. As a user you want to continue and hope for the best
24
+ (logging the error). As a developer you want to see how you can fix
25
+ the problem. Waiting for a full run and checking the logs is tedious.
26
+ The logger can be helpful here, and avoids sticking 'temporary'
27
+ solutions in code.
20
28
 
21
29
  bio-logger builds up on log4r functionality, which comes with multiple
22
30
  handlers, such as a rotating and remote logging, and is thread-safe.
23
- Next to adding behaviours, bio-logger introduces a more fine-grained
31
+ Next to adding filtering and behaviours, bio-logger introduces a more fine-grained
24
32
  approach for logging errors. I.e. within 'debug', 'info', 'warn',
25
- 'error' and 'fatal', an additional value 1..9 can be set to limit
33
+ 'error' and 'fatal', an additional value (the sub_level) can be set to limit
26
34
  output and logging. This, again, can be helpful when dealing with huge
27
- log files. Switch a not so important and validated DEBUG, INFO or
28
- WARN, to a higher sub level will take it out of the logs. This can
29
- also make sense when deploying applications under different scenarios.
30
-
31
- Log4r is useful, compared to the standard Ruby logger,
32
- because it allows you to set reporting leaves by log type. I.e. if
33
- everything in BioRuby works, except for the BLAST parser, or some
34
- plugin, the logger
35
+ log files. One way is to switch a not so important and validated
36
+ DEBUG, INFO or WARN, to a higher sub level will take it out of the
37
+ logs. Another option is to log only the messages of a certain value,
38
+ or to regex on the message - i.e. you get othogonal differentiation of
39
+ values and types (see the filter example below). This can also make
40
+ sense when deploying applications under different scenarios.
41
+
42
+ Log4r is useful, compared to the standard Ruby logger, because it
43
+ allows you to set reporting leaves by log type. I.e. if everything in
44
+ BioRuby works, except for the BLAST parser, or some plugin, the logger
35
45
  can be tuned only to log BLAST debug level, and everything else at
36
46
  normal level.
37
47
 
@@ -39,7 +49,8 @@ In other words, bio-logger helps in tracking down problems and
39
49
  provide a way of avoiding sprinkling $stderr.print statements through
40
50
  the code base.
41
51
 
42
- To support applications, bio-logger can also parse command line switches:
52
+ To support applications, bio-logger can also help parse command line
53
+ switches:
43
54
 
44
55
  add (multiple) loggers:
45
56
 
@@ -51,6 +62,8 @@ specify global log level:
51
62
  --trace debug Show all messages
52
63
  --trace warn Show messages more serious than 'warn'
53
64
  --trace warn:3 Show messaged more serious that 'warn' level 3
65
+ --trace "=3" Show all messages with sub-level==3
66
+ --trace "=sub_level == 3 or level <= ERROR" Set filter
54
67
 
55
68
  overrides:
56
69
 
@@ -103,7 +116,7 @@ streams. It is also possible to change behaviours by module.
103
116
  log.fatal "This is a message with level FATAL"
104
117
  log.warn3 "This is a message with level WARN:3"
105
118
 
106
- # Restrict output to WARN:3
119
+ # Restrict output to messages <=WARN:3
107
120
  log.level = WARN
108
121
  log.sub_level = 3
109
122
  log.info("This is a message with level INFO") # not logged
@@ -111,6 +124,15 @@ streams. It is also possible to change behaviours by module.
111
124
  log.warn1("This is a message with level WARN:1") # logged
112
125
  log.warn("This is a message with level WARN") # logged
113
126
 
127
+ # Restrict output for DEBUG, INFO, WARN to sub_level 3
128
+ log.filter { | level, sub_level, msg | sub_level == 3 or level <= ERROR }
129
+ log.warn8("This is a message with level WARN:8") # not logged
130
+ log.warn3("This is a message with level WARN:3") # logged
131
+ log.warn1("This is a message with level WARN:1") # not logged
132
+ log.info3("This is a message with level INFO:3") # logged
133
+ log.error("This is a message with level ERROR") # logged
134
+ log.reset_filter
135
+
114
136
  # Fetch the BLAST logger (assuming it exists)
115
137
  blastlog = LoggerPlus['blast']
116
138
  blastlog.warn("This is a message with level WARN") # logged
data/Rakefile CHANGED
@@ -21,8 +21,8 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.authors = ["Pjotr Prins"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
23
23
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- gem.add_runtime_dependency 'log4r', '> 1.1.6'
25
- gem.add_development_dependency 'rspec', '> 1.2.3'
24
+ # gem.add_runtime_dependency 'log4r', '> 1.1.6'
25
+ # gem.add_development_dependency 'rspec', '>= 2.3.0'
26
26
  end
27
27
  Jeweler::RubygemsDotOrgTasks.new
28
28
 
@@ -31,6 +31,7 @@ Rake::TestTask.new(:test) do |test|
31
31
  test.libs << 'lib' << 'test'
32
32
  test.pattern = 'test/**/test_*.rb'
33
33
  test.verbose = true
34
+ Kernel.system('rspec spec/*.rb')
34
35
  end
35
36
 
36
37
  require 'rcov/rcovtask'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.9.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bio-logger}
8
- s.version = "0.6.1"
8
+ s.version = "0.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pjotr Prins"]
12
- s.date = %q{2011-01-12}
12
+ s.date = %q{2011-01-17}
13
13
  s.description = %q{Log4r wrapper for BioRuby}
14
14
  s.email = %q{pjotr.public01@thebird.nl}
15
15
  s.extra_rdoc_files = [
@@ -28,8 +28,10 @@ Gem::Specification.new do |s|
28
28
  "lib/bio-logger.rb",
29
29
  "lib/bio/log/logger.rb",
30
30
  "lib/bio/log/loggercli.rb",
31
+ "lib/bio/log/loggerfilter.rb",
31
32
  "lib/bio/log/loggersublevels.rb",
32
33
  "lib/bio/log/loggerusers.rb",
34
+ "lib/bio/log/patchlog4r.rb",
33
35
  "spec/biologger_cli_spec.rb",
34
36
  "spec/biologger_spec.rb",
35
37
  "test/helper.rb",
@@ -52,30 +54,27 @@ Gem::Specification.new do |s|
52
54
  s.specification_version = 3
53
55
 
54
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<log4r>, [">= 1.1.9"])
55
58
  s.add_development_dependency(%q<shoulda>, [">= 0"])
56
59
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
57
60
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
58
61
  s.add_development_dependency(%q<rcov>, [">= 0"])
59
- s.add_development_dependency(%q<bio>, [">= 1.4.1"])
60
- s.add_runtime_dependency(%q<log4r>, ["> 1.1.6"])
61
- s.add_development_dependency(%q<rspec>, ["> 1.2.3"])
62
+ s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
62
63
  else
64
+ s.add_dependency(%q<log4r>, [">= 1.1.9"])
63
65
  s.add_dependency(%q<shoulda>, [">= 0"])
64
66
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
67
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
68
  s.add_dependency(%q<rcov>, [">= 0"])
67
- s.add_dependency(%q<bio>, [">= 1.4.1"])
68
- s.add_dependency(%q<log4r>, ["> 1.1.6"])
69
- s.add_dependency(%q<rspec>, ["> 1.2.3"])
69
+ s.add_dependency(%q<rspec>, [">= 2.3.0"])
70
70
  end
71
71
  else
72
+ s.add_dependency(%q<log4r>, [">= 1.1.9"])
72
73
  s.add_dependency(%q<shoulda>, [">= 0"])
73
74
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
74
75
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
75
76
  s.add_dependency(%q<rcov>, [">= 0"])
76
- s.add_dependency(%q<bio>, [">= 1.4.1"])
77
- s.add_dependency(%q<log4r>, ["> 1.1.6"])
78
- s.add_dependency(%q<rspec>, ["> 1.2.3"])
77
+ s.add_dependency(%q<rspec>, [">= 2.3.0"])
79
78
  end
80
79
  end
81
80
 
@@ -1,12 +1,12 @@
1
-
2
1
  require "rubygems"
3
2
  begin
4
- gem "log4r" , "> 1.1.8"
3
+ gem "log4r"
5
4
  rescue
6
5
  $stderr.print "log4r not installed, bailing out...\n"
7
6
  exit 1
8
7
  end
9
8
 
10
9
  require 'log4r'
10
+ require 'bio/log/patchlog4r'
11
11
  require 'bio/log/logger'
12
12
  require 'bio/log/loggercli'
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'bio/log/loggersublevels'
3
+ require 'bio/log/loggerfilter'
3
4
  require 'bio/log/loggerusers'
4
5
  require 'bio/log/loggercli'
5
6
 
@@ -12,6 +13,14 @@ module Bio
12
13
  # Derived from the Log4r Logger class
13
14
  class LoggerPlus < Logger
14
15
  include LoggerSubLevels
16
+ include LoggerFilter
17
+
18
+ def default_level
19
+ # Log4r::Logger::DEBUG
20
+ 6
21
+ end
22
+ def default_sub_level
23
+ end
15
24
 
16
25
  def debug_ msg, options = {}
17
26
  if options[:act]
@@ -53,6 +62,10 @@ module Bio
53
62
  end
54
63
  end
55
64
 
65
+ def [] name
66
+ super
67
+ end
68
+
56
69
  end
57
70
 
58
71
  end
@@ -24,27 +24,50 @@ module Bio
24
24
 
25
25
  # Parse and store trace options
26
26
  def CLI::trace s
27
+ level = nil
27
28
  sub_level = nil
29
+ filter = nil
28
30
 
29
31
  opts = {}
32
+ # ---- split fields
30
33
  a = s.split(':')
31
- if a.last =~ /^\d+$/
34
+ if a.last =~ /^=(\d+)$/
35
+ # ---- set exact filter
36
+ filter = "sub_level==#{$1}"
37
+ a.pop
38
+ elsif a.last =~ /^=/
39
+ # ---- set filter
40
+ filter = $'
41
+ a.pop
42
+ elsif a.last =~ /^\d+$/
43
+ # ---- the last field is the sub level
32
44
  sub_level = a.pop.to_i
45
+ # ---- The fore-last field is the level
46
+ level = a.pop.downcase
47
+ else
48
+ level = a.pop.downcase
33
49
  end
34
- level = a.pop.downcase
50
+ # ---- If there is another field it contains logger name(s)
51
+ # otherwise it is a global
35
52
  outputter =
36
53
  if a.size == 2
37
54
  a.shift
38
55
  end
39
56
  if a.size == 0
40
- a = [:default]
57
+ a = [:default] # global
41
58
  else
42
- a = a[0].split(',')
59
+ a = a[0].split(',') # one or more logger name(s)
43
60
  end
61
+ # ---- update every logger
44
62
  a.each do | type |
45
- opts[type] = { :level => level, :sub_level => sub_level }
63
+ opts[type] = {}
64
+ opts[type][:level] = level if level
65
+ opts[type][:sub_level] = sub_level if sub_level
66
+ opts[type][:filter] = filter if filter
46
67
  opts[type][:outputter_name] = outputter if outputter
68
+ # p [type,opts[type]]
47
69
  end
70
+ # ---- Set the globals
48
71
  LoggerPlusGlobal.instance.trace ||= {}
49
72
  LoggerPlusGlobal.instance.trace = LoggerPlusGlobal.instance.trace.merge(opts)
50
73
  end
@@ -59,6 +82,7 @@ module Bio
59
82
  default = trace[:default] if trace[:default]
60
83
  trace[logname] ||= {} if logname
61
84
  trace.each do | name, opts |
85
+ # p [name, opts]
62
86
  next if name == :default
63
87
  logger_type = type
64
88
  logger_type = default[:outputter_name] if default[:outputter_name]
@@ -75,6 +99,14 @@ module Bio
75
99
  end
76
100
  set_levels(logger, default) if default
77
101
  set_levels(logger, opts)
102
+ filter = default[:filter]
103
+ filter = opts[:filter] if opts[:filter]
104
+ if filter
105
+ # p filter
106
+ filter2 = "logger.filter { |level,sub_level,msg| #{filter} }"
107
+ # p filter2
108
+ eval(filter2)
109
+ end
78
110
  end
79
111
  end
80
112
 
@@ -0,0 +1,36 @@
1
+
2
+ module Bio
3
+ module Log
4
+
5
+ # The filter logger changes behaviour
6
+ module LoggerFilter
7
+
8
+ def filter &filter_func
9
+ @use_filter = filter_func
10
+ @outputters.each do | out |
11
+ # p [:adding_filter_to,out]
12
+ out.class.send(:define_method, :filtered?) do |l,s,m|
13
+ # p [:called,l,s,m]
14
+ filter_func.call(l,s,m)
15
+ end
16
+ raise 'hell' if !out.class.method_defined?(:filtered?)
17
+ end
18
+ @level = default_level # will recreate logger methods
19
+ @sub_level = default_sub_level
20
+ end
21
+
22
+ def reset_filter
23
+ @use_filter = nil
24
+ @outputters.each do | out |
25
+ if out.class.method_defined?(:filtered?)
26
+ out.class.send(:remove_method, :filtered?)
27
+ end
28
+ end
29
+ @level = default_level # will recreate logger methods
30
+ @sub_level = default_sub_level
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -9,142 +9,187 @@ module Bio
9
9
  attr_accessor :sub_level
10
10
 
11
11
  def debug1(s)
12
+ return nil if @use_filter and !@use_filter.call(DEBUG,1,s)
12
13
  debug(s) if !sub_level or sub_level >= 1
13
14
  end
14
15
  def debug2(s)
16
+ return nil if @use_filter and !@use_filter.call(DEBUG,2,s)
15
17
  debug(s) if !sub_level or sub_level >= 2
16
18
  end
17
19
  def debug3(s)
20
+ return nil if @use_filter and !@use_filter.call(DEBUG,3,s)
18
21
  debug(s) if !sub_level or sub_level >= 3
19
22
  end
20
23
  def debug4(s)
24
+ return nil if @use_filter and !@use_filter.call(DEBUG,4,s)
21
25
  debug(s) if !sub_level or sub_level >= 4
22
26
  end
23
27
  def debug5(s)
28
+ return nil if @use_filter and !@use_filter.call(DEBUG,5,s)
24
29
  debug(s) if !sub_level or sub_level >= 5
25
30
  end
26
31
  def debug6(s)
32
+ return nil if @use_filter and !@use_filter.call(DEBUG,6,s)
27
33
  debug(s) if !sub_level or sub_level >= 6
28
34
  end
29
35
  def debug7(s)
36
+ return nil if @use_filter and !@use_filter.call(DEBUG,7,s)
30
37
  debug(s) if !sub_level or sub_level >= 7
31
38
  end
32
39
  def debug8(s)
40
+ return nil if @use_filter and !@use_filter.call(DEBUG,8,s)
33
41
  debug(s) if !sub_level or sub_level >= 8
34
42
  end
35
43
  def debug9(s)
44
+ return nil if @use_filter and !@use_filter.call(DEBUG,9,s)
36
45
  debug(s) if !sub_level or sub_level >= 9
37
46
  end
38
47
 
39
48
  def info1(s)
49
+ return nil if @use_filter and !@use_filter.call(INFO,1,s)
40
50
  info(s) if !sub_level or sub_level >= 1
41
51
  end
42
52
  def info2(s)
53
+ return nil if @use_filter and !@use_filter.call(INFO,2,s)
43
54
  info(s) if !sub_level or sub_level >= 2
44
55
  end
45
56
  def info3(s)
57
+ return nil if @use_filter and !@use_filter.call(INFO,3,s)
46
58
  info(s) if !sub_level or sub_level >= 3
47
59
  end
48
60
  def info4(s)
61
+ return nil if @use_filter and !@use_filter.call(INFO,4,s)
49
62
  info(s) if !sub_level or sub_level >= 4
50
63
  end
51
64
  def info5(s)
65
+ return nil if @use_filter and !@use_filter.call(INFO,5,s)
52
66
  info(s) if !sub_level or sub_level >= 5
53
67
  end
54
68
  def info6(s)
69
+ return nil if @use_filter and !@use_filter.call(INFO,6,s)
55
70
  info(s) if !sub_level or sub_level >= 6
56
71
  end
57
72
  def info7(s)
73
+ return nil if @use_filter and !@use_filter.call(INFO,7,s)
58
74
  info(s) if !sub_level or sub_level >= 7
59
75
  end
60
76
  def info8(s)
77
+ return nil if @use_filter and !@use_filter.call(INFO,8,s)
61
78
  info(s) if !sub_level or sub_level >= 8
62
79
  end
63
80
  def info9(s)
81
+ return nil if @use_filter and !@use_filter.call(INFO,9,s)
64
82
  info(s) if !sub_level or sub_level >= 9
65
83
  end
66
84
 
67
85
  def warn1(s)
86
+ return nil if @use_filter and !@use_filter.call(WARN,1,s)
68
87
  warn(s) if !sub_level or sub_level >= 1
69
88
  end
70
89
  def warn2(s)
90
+ return nil if @use_filter and !@use_filter.call(WARN,2,s)
71
91
  warn(s) if !sub_level or sub_level >= 2
72
92
  end
73
93
  def warn3(s)
94
+ return nil if @use_filter and !@use_filter.call(WARN,3,s)
74
95
  warn(s) if !sub_level or sub_level >= 3
75
96
  end
76
97
  def warn4(s)
98
+ return nil if @use_filter and !@use_filter.call(WARN,4,s)
77
99
  warn(s) if !sub_level or sub_level >= 4
78
100
  end
79
101
  def warn5(s)
102
+ return nil if @use_filter and !@use_filter.call(WARN,5,s)
80
103
  warn(s) if !sub_level or sub_level >= 5
81
104
  end
82
105
  def warn6(s)
106
+ return nil if @use_filter and !@use_filter.call(WARN,6,s)
83
107
  warn(s) if !sub_level or sub_level >= 6
84
108
  end
85
109
  def warn7(s)
110
+ return nil if @use_filter and !@use_filter.call(WARN,7,s)
86
111
  warn(s) if !sub_level or sub_level >= 7
87
112
  end
88
113
  def warn8(s)
114
+ return nil if @use_filter and !@use_filter.call(WARN,8,s)
89
115
  warn(s) if !sub_level or sub_level >= 8
90
116
  end
91
117
  def warn9(s)
118
+ return nil if @use_filter and !@use_filter.call(WARN,9,s)
92
119
  warn(s) if !sub_level or sub_level >= 9
93
120
  end
94
121
 
95
122
  def error1(s)
123
+ return nil if @use_filter and !@use_filter.call(ERROR,1,s)
96
124
  error(s) if !sub_level or sub_level >= 1
97
125
  end
98
126
  def error2(s)
127
+ return nil if @use_filter and !@use_filter.call(ERROR,2,s)
99
128
  error(s) if !sub_level or sub_level >= 2
100
129
  end
101
130
  def error3(s)
131
+ return nil if @use_filter and !@use_filter.call(ERROR,3,s)
102
132
  error(s) if !sub_level or sub_level >= 3
103
133
  end
104
134
  def error4(s)
135
+ return nil if @use_filter and !@use_filter.call(ERROR,4,s)
105
136
  error(s) if !sub_level or sub_level >= 4
106
137
  end
107
138
  def error5(s)
139
+ return nil if @use_filter and !@use_filter.call(ERROR,5,s)
108
140
  error(s) if !sub_level or sub_level >= 5
109
141
  end
110
142
  def error6(s)
143
+ return nil if @use_filter and !@use_filter.call(ERROR,6,s)
111
144
  error(s) if !sub_level or sub_level >= 6
112
145
  end
113
146
  def error7(s)
147
+ return nil if @use_filter and !@use_filter.call(ERROR,7,s)
114
148
  error(s) if !sub_level or sub_level >= 7
115
149
  end
116
150
  def error8(s)
151
+ return nil if @use_filter and !@use_filter.call(ERROR,8,s)
117
152
  error(s) if !sub_level or sub_level >= 8
118
153
  end
119
154
  def error9(s)
155
+ return nil if @use_filter and !@use_filter.call(ERROR,9,s)
120
156
  error(s) if !sub_level or sub_level >= 9
121
157
  end
122
158
 
123
159
  def fatal1(s)
160
+ return nil if @use_filter and !@use_filter.call(FATAL,1,s)
124
161
  fatal(s) if !sub_level or sub_level >= 1
125
162
  end
126
163
  def fatal2(s)
164
+ return nil if @use_filter and !@use_filter.call(FATAL,2,s)
127
165
  fatal(s) if !sub_level or sub_level >= 2
128
166
  end
129
167
  def fatal3(s)
168
+ return nil if @use_filter and !@use_filter.call(FATAL,3,s)
130
169
  fatal(s) if !sub_level or sub_level >= 3
131
170
  end
132
171
  def fatal4(s)
172
+ return nil if @use_filter and !@use_filter.call(FATAL,4,s)
133
173
  fatal(s) if !sub_level or sub_level >= 4
134
174
  end
135
175
  def fatal5(s)
176
+ return nil if @use_filter and !@use_filter.call(FATAL,5,s)
136
177
  fatal(s) if !sub_level or sub_level >= 5
137
178
  end
138
179
  def fatal6(s)
180
+ return nil if @use_filter and !@use_filter.call(FATAL,6,s)
139
181
  fatal(s) if !sub_level or sub_level >= 6
140
182
  end
141
183
  def fatal7(s)
184
+ return nil if @use_filter and !@use_filter.call(FATAL,7,s)
142
185
  fatal(s) if !sub_level or sub_level >= 7
143
186
  end
144
187
  def fatal8(s)
188
+ return nil if @use_filter and !@use_filter.call(FATAL,8,s)
145
189
  fatal(s) if !sub_level or sub_level >= 8
146
190
  end
147
191
  def fatal9(s)
192
+ return nil if @use_filter and !@use_filter.call(FATAL,9,s)
148
193
  fatal(s) if !sub_level or sub_level >= 9
149
194
  end
150
195
 
@@ -30,7 +30,7 @@ module Bio
30
30
  class FailOnError < NormalUser
31
31
  def error logger, msg
32
32
  logger.error msg
33
- raise FailOnErrorException
33
+ raise FailOnErrorException,msg
34
34
  end
35
35
 
36
36
  def fatal logger, msg
@@ -0,0 +1,40 @@
1
+ module Log4r
2
+ class Outputter < Monitor
3
+
4
+ # Log4r creates the logging methods dynamically - quite cleverly creating
5
+ # only those methods that are required, but not that transparent.
6
+ #
7
+ # To add filter support we 'monkey patch' the original implementation of
8
+ # +define_log+ in 'outputterfactory.rb' by adding in the filter call.
9
+ # This slows down the run time, but that is not so important.
10
+ #
11
+ class OutputterFactory
12
+ # original comment: we need to synch the actual write/format for thread saftyness
13
+ def self.define_log(mname, level, out)
14
+ return if mname == 'off' || mname == 'all'
15
+ # p [mname,level,out]
16
+ #
17
+ # At runtime, self and logevent are available to the method:
18
+ # [:self, #<Log4r::StderrOutputter:0x9f8975c @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x9f89694>, @name="stderr", @level=0, @formatter=#<Log4r::DefaultFormatter:0x9f7c174 @depth=7>, @out=#<IO:<STDERR>>>]
19
+ # [:logevent, #<Log4r::LogEvent:0xa198de0 @data="As Developer ERROR should fail", @tracer=nil, @level=4, @name="mylog", @fullname="mylog">]
20
+
21
+ mstr =
22
+ %-
23
+ def out.#{mname}(logevent)
24
+ if self.class.method_defined?(:filtered?)
25
+ # p logevent
26
+ if !filtered?(logevent.level,nil,logevent.data)
27
+ # p "**** returning nil for "+logevent.data
28
+ return nil
29
+ end
30
+ end
31
+ canonical_log(logevent)
32
+ end
33
+ -
34
+ module_eval mstr
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
@@ -33,19 +33,27 @@ describe Bio::Log::CLI, "bio-logger command line parsing" do
33
33
  end
34
34
  it "should parse --trace debug to show all messages" do
35
35
  CLI.trace("debug")
36
- @global.trace[:default].should == { :level => 'debug', :sub_level => nil }
36
+ @global.trace[:default].should == { :level => 'debug' }
37
37
  end
38
38
  it "should parse --trace warn to show how messages more serious than 'warn'" do
39
39
  CLI.trace("warn")
40
- @global.trace[:default].should == { :level => 'warn', :sub_level => nil }
40
+ @global.trace[:default].should == { :level => 'warn' }
41
41
  end
42
42
  it "should parse --trace warn:3 to show messaged more serious that 'warn' level 3" do
43
43
  CLI.trace("warn:3")
44
44
  @global.trace[:default].should == { :level => 'warn', :sub_level => 3 }
45
45
  end
46
+ it "should parse --trace =3 to show level 3 only" do
47
+ CLI.trace("=3")
48
+ @global.trace[:default].should == { :filter => "sub_level==3" }
49
+ end
50
+ it "should parse --trace \"=sub_level == 3 or level <= ERROR\"" do
51
+ CLI.trace("=sub_level == 3 or level <= ERROR")
52
+ @global.trace[:default].should == { :filter => "sub_level == 3 or level <= ERROR" }
53
+ end
46
54
  it "should parse --trace blast:debug to override level for 'blast'" do
47
55
  CLI.trace("blast:debug")
48
- @global.trace.should == {"blast"=>{:level=>"debug", :sub_level=>nil}}
56
+ @global.trace.should == {"blast"=>{:level=>"debug"}}
49
57
  end
50
58
  it "should parse --trace gff3:info:5 to override level for 'gff3' to info level 5" do
51
59
  CLI.trace("gff3:info:5")
@@ -55,10 +63,14 @@ describe Bio::Log::CLI, "bio-logger command line parsing" do
55
63
  CLI.trace("blast,gff3:debug:5")
56
64
  @global.trace.should == {"blast"=>{:level=>"debug", :sub_level=>5}, "gff3"=>{:level=>"debug", :sub_level=>5}}
57
65
  end
66
+ it "should parse --trace \"blast:=sub_level == 3 or level <= ERROR\"" do
67
+ CLI.trace("blast:=sub_level == 3 or level <= ERROR")
68
+ @global.trace['blast'].should == { :filter => "sub_level == 3 or level <= ERROR" }
69
+ end
58
70
  it "should parse --trace stderr:blast:debug to override level for 'blast' on stderr" do
59
71
  CLI.trace("stderr:blast:debug")
60
72
  @global.trace.should ==
61
- {"blast"=>{:level=>"debug", :sub_level=>nil, :outputter_name=>"stderr"}}
73
+ {"blast"=>{:level=>"debug", :outputter_name=>"stderr"}}
62
74
  end
63
75
  it "should parse --trace stderr:blast,gff3:debug:1 to override level for 'blast' on stderr" do
64
76
  CLI.trace("stderr:blast,gff3:debug:1")
@@ -33,6 +33,7 @@ describe Bio::Log, "logs" do
33
33
  after(:all) do
34
34
  File.unlink("file.log")
35
35
  File.unlink("TestSize000001.log")
36
+ @mylog.reset_filter
36
37
  end
37
38
 
38
39
  it "should have a stderr logger" do
@@ -77,6 +78,28 @@ describe Bio::Log, "logs" do
77
78
  @mylog.info("This is a message with level INFO").should_not == nil
78
79
  @mylog.warn8("This is a message with level WARN:8").should_not == nil
79
80
  end
81
+ it "should allow for a filter" do
82
+ @mylog.filter { |l,s,m| l==INFO }
83
+ @mylog.info("This is a level filtered message with level INFO")
84
+ @mylog.warn("NO DISPLAY: This is a level filtered message with level WARN")
85
+ @mylog.error("NO DISPLAY: This is a level filtered message with level ERROR")
86
+
87
+ @mylog.filter { |l,s,m| m =~ /filtered/ }
88
+ @mylog.info("NO DISPLAY: This is a Filtered message with level XXX")
89
+ @mylog.info3("DISPLAY This is a filtered message with level XXX")
90
+
91
+ @mylog.filter { |l,s,m| s==3 }
92
+ @mylog.info("NO DISPLAY: This is a filtered message with level INFO")
93
+ @mylog.info3("DISPLAY This is a filtered message with level INFO:3")
94
+ @mylog.warn8("NO DISPLAY: This is a filtered message with level WARN:8")
95
+ @mylog.warn3("DISPLAY This is a filtered message with level WARN:3")
96
+ @mylog.warn1("NO DISPLAY: This is a filtered message with level WARN:1")
97
+ @mylog.warn("NO DISPLAY: This is a filtered message with level WARN")
98
+ @mylog.error("NO DISPLAY: This is a filtered message with level ERROR")
99
+ @mylog.reset_filter
100
+ @mylog.info("DISPLAY: This is an unfiltered message with level INFO").should_not == nil
101
+ @mylog.warn8("DISPLAY: This is an unfiltered message with level WARN:8").should_not == nil
102
+ end
80
103
  it "should override level for 'blast' to info level 5" do
81
104
  log = LoggerPlus['blast']
82
105
  log.should_not == nil
@@ -1,7 +1,9 @@
1
1
  require 'helper'
2
2
 
3
- class TestBioLogger < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end
3
+ # See the ./spec dir
4
+ #
5
+ # class TestBioLogger < Test::Unit::TestCase
6
+ # should "probably rename this file and start testing for real" do
7
+ # flunk "hey buddy, you should probably rename this file and start testing for real"
8
+ # end
9
+ # end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 9
8
+ - 0
9
+ version: 0.9.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Pjotr Prins
@@ -14,39 +14,39 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-12 00:00:00 +01:00
17
+ date: 2011-01-17 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: shoulda
21
+ name: log4r
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
- - 0
29
- version: "0"
30
- type: :development
28
+ - 1
29
+ - 1
30
+ - 9
31
+ version: 1.1.9
32
+ type: :runtime
31
33
  prerelease: false
32
34
  version_requirements: *id001
33
35
  - !ruby/object:Gem::Dependency
34
- name: bundler
36
+ name: shoulda
35
37
  requirement: &id002 !ruby/object:Gem::Requirement
36
38
  none: false
37
39
  requirements:
38
- - - ~>
40
+ - - ">="
39
41
  - !ruby/object:Gem::Version
40
42
  segments:
41
- - 1
42
- - 0
43
43
  - 0
44
- version: 1.0.0
44
+ version: "0"
45
45
  type: :development
46
46
  prerelease: false
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: jeweler
49
+ name: bundler
50
50
  requirement: &id003 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
@@ -54,70 +54,55 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  segments:
56
56
  - 1
57
- - 5
58
- - 2
59
- version: 1.5.2
57
+ - 0
58
+ - 0
59
+ version: 1.0.0
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: rcov
64
+ name: jeweler
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
68
- - - ">="
68
+ - - ~>
69
69
  - !ruby/object:Gem::Version
70
70
  segments:
71
- - 0
72
- version: "0"
71
+ - 1
72
+ - 5
73
+ - 2
74
+ version: 1.5.2
73
75
  type: :development
74
76
  prerelease: false
75
77
  version_requirements: *id004
76
78
  - !ruby/object:Gem::Dependency
77
- name: bio
79
+ name: rcov
78
80
  requirement: &id005 !ruby/object:Gem::Requirement
79
81
  none: false
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
83
85
  segments:
84
- - 1
85
- - 4
86
- - 1
87
- version: 1.4.1
86
+ - 0
87
+ version: "0"
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: *id005
91
- - !ruby/object:Gem::Dependency
92
- name: log4r
93
- requirement: &id006 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ">"
97
- - !ruby/object:Gem::Version
98
- segments:
99
- - 1
100
- - 1
101
- - 6
102
- version: 1.1.6
103
- type: :runtime
104
- prerelease: false
105
- version_requirements: *id006
106
91
  - !ruby/object:Gem::Dependency
107
92
  name: rspec
108
- requirement: &id007 !ruby/object:Gem::Requirement
93
+ requirement: &id006 !ruby/object:Gem::Requirement
109
94
  none: false
110
95
  requirements:
111
- - - ">"
96
+ - - ">="
112
97
  - !ruby/object:Gem::Version
113
98
  segments:
114
- - 1
115
99
  - 2
116
100
  - 3
117
- version: 1.2.3
101
+ - 0
102
+ version: 2.3.0
118
103
  type: :development
119
104
  prerelease: false
120
- version_requirements: *id007
105
+ version_requirements: *id006
121
106
  description: Log4r wrapper for BioRuby
122
107
  email: pjotr.public01@thebird.nl
123
108
  executables: []
@@ -139,8 +124,10 @@ files:
139
124
  - lib/bio-logger.rb
140
125
  - lib/bio/log/logger.rb
141
126
  - lib/bio/log/loggercli.rb
127
+ - lib/bio/log/loggerfilter.rb
142
128
  - lib/bio/log/loggersublevels.rb
143
129
  - lib/bio/log/loggerusers.rb
130
+ - lib/bio/log/patchlog4r.rb
144
131
  - spec/biologger_cli_spec.rb
145
132
  - spec/biologger_spec.rb
146
133
  - test/helper.rb
@@ -159,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
146
  requirements:
160
147
  - - ">="
161
148
  - !ruby/object:Gem::Version
162
- hash: 142425075
149
+ hash: -277148543
163
150
  segments:
164
151
  - 0
165
152
  version: "0"