bio-logger 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ gem "bio", ">= 1.4.1"
14
+ end
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ bio (1.4.1)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bio (>= 1.4.1)
19
+ bundler (~> 1.0.0)
20
+ jeweler (~> 1.5.2)
21
+ rcov
22
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Pjotr Prins
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,174 @@
1
+ = bio-logger
2
+
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
6
+
7
+ * NormalUser
8
+ * Developer (or FailOnError)
9
+ * WebServer
10
+ * FaultTolerant systems
11
+
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.
20
+
21
+ bio-logger builds up on log4r functionality, which comes with multiple
22
+ handlers, such as a rotating and remote logging, and is thread-safe.
23
+ Next to adding behaviours, bio-logger introduces a more fine-grained
24
+ approach for logging errors. I.e. within 'debug', 'info', 'warn',
25
+ 'error' and 'fatal', an additional value 1..9 can be set to limit
26
+ 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
+ can be tuned only to log BLAST debug level, and everything else at
36
+ normal level.
37
+
38
+ In other words, bio-logger helps in tracking down problems and
39
+ provide a way of avoiding sprinkling $stderr.print statements through
40
+ the code base.
41
+
42
+ To support applications, bio-logger can also parse command line switches:
43
+
44
+ add (multiple) loggers:
45
+
46
+ --logger stderr Add stderr logger
47
+ --logger filen Add filename logger
48
+
49
+ specify global log level:
50
+
51
+ --trace debug Show all messages
52
+ --trace warn Show messages more serious than 'warn'
53
+ --trace warn:3 Show messaged more serious that 'warn' level 3
54
+
55
+ overrides:
56
+
57
+ --trace gff3:info:5 Override level for 'gff3' to info level 5
58
+ --trace blast:debug Override level for 'blast'
59
+ --trace blast,gff3:debug Override level for 'blast' and 'gff3'
60
+ --trace stderr:blast:debug Override level for 'blast' on stderr
61
+
62
+ Earlier described behaviour, or 'acting', can be changed. This
63
+ normally happens through library calls. There is one command line
64
+ switch, which changes log-act:
65
+
66
+ --log-act FailOnError Modify the logger for development
67
+
68
+ which will cause, for example, 'error' and 'fatal' to fail during
69
+ development, for special calls to the logger (described below).
70
+ New behaviour can be implemented by deriving from an existing class.
71
+
72
+ == Install bio-logger
73
+
74
+ gem install bio-logger
75
+
76
+ == Bio::Log API
77
+
78
+ In code there are more options. For example, it is possible to define
79
+ multiple output streams, or split out different loggers to different
80
+ streams. It is also possible to change behaviours by module.
81
+
82
+ require 'bio-logger'
83
+ include Bio::Log
84
+
85
+ # ==== Create loggers
86
+ log = LoggerPlus.new 'mylog'
87
+ log.outputters = Outputter.stderr
88
+
89
+ # create a second rotating log for BLAST
90
+ config = {
91
+ "filename" => "log/blast.log", # make sure the dir exists!
92
+ "maxsize" => 16000, # max file size
93
+ "trunc" => false # don't delete log
94
+ }
95
+ log2 = LoggerPlus.new 'blast'
96
+ log2.outputters = RollingFileOutputter.new("blast", config)
97
+
98
+ # ==== Output messages on 'mylog'
99
+ log.debug "This is a message with level DEBUG"
100
+ log.info "This is a message with level INFO"
101
+ log.warn "This is a message with level WARN"
102
+ log.error "This is a message with level ERROR"
103
+ log.fatal "This is a message with level FATAL"
104
+ log.warn3 "This is a message with level WARN:3"
105
+
106
+ # Restrict output to WARN:3
107
+ log.level = WARN
108
+ log.sub_level = 3
109
+ log.info("This is a message with level INFO") # not logged
110
+ log.warn8("This is a message with level WARN:8") # not logged
111
+ log.warn1("This is a message with level WARN:1") # logged
112
+ log.warn("This is a message with level WARN") # logged
113
+
114
+ # Fetch the BLAST logger (assuming it exists)
115
+ blastlog = LoggerPlus['blast']
116
+ blastlog.warn("This is a message with level WARN") # logged
117
+
118
+ # Special logging behaviour
119
+ blastlog.error_("ERROR should not fail",:act => NormalUser.new)
120
+ dev = FailOnError.new
121
+ blastlog.info_("INFO should not fail",:act => dev)
122
+ blastlog.error_("As Developer ERROR should fail",:act => dev)
123
+
124
+ For parsing command line options with the OptionParser:
125
+
126
+ opts.on("--logger filename",String,"Log to file (default STDOUT)") do | name |
127
+ Bio::Log::CLI.logger(name)
128
+ end
129
+
130
+ opts.on("--trace options",String,"Set log level (default INFO, see bio-logger)") do | s |
131
+ Bio::Log::CLI.trace(s)
132
+ end
133
+
134
+ opts.on("-q", "--quiet", "Run quietly") do |q|
135
+ Bio::Log::CLI.trace('error')
136
+ end
137
+
138
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
139
+ Bio::Log::CLI.trace('info')
140
+ end
141
+
142
+ # Realize settings
143
+ Bio::Log::CLI.configure('mylog')
144
+
145
+ == Documentation
146
+
147
+ The log4r documentation and source code can be used, as this Logger
148
+ implementation passes everything down, except for the added methods.
149
+
150
+ See http://log4r.rubyforge.org/
151
+
152
+ See also the Specs in ./spec for more examples. Run the Specs with
153
+
154
+ rspec spec/*.rb
155
+
156
+ == TODO
157
+
158
+ The current version is used in BioRuby parser plugins (e.g.
159
+ http://github.com/pjotrp/bioruby-gff3-plugin/).
160
+
161
+ It may be
162
+ interesting to run loggers as actors, so the are fully parallelized
163
+ with the main application.
164
+
165
+ == Cite
166
+
167
+ If you use this software, please cite http://dx.doi.org/10.1093/bioinformatics/btq475
168
+
169
+ == Copyright
170
+
171
+ Copyright (C) 2011 Pjotr Prins <pjotr.prins@thebird.nl>
172
+
173
+ See LICENSE.txt for further details.
174
+
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "bio-logger"
16
+ gem.homepage = "http://github.com/pjotrp/bioruby-logger"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Log4r wrapper for BioRuby}
19
+ gem.description = %Q{Log4r wrapper for BioRuby}
20
+ gem.email = "pjotr.public01@thebird.nl"
21
+ gem.authors = ["Pjotr Prins"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
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'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "bio-logger #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.0
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{bio-logger}
8
+ s.version = "0.6.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Pjotr Prins"]
12
+ s.date = %q{2011-01-12}
13
+ s.description = %q{Log4r wrapper for BioRuby}
14
+ s.email = %q{pjotr.public01@thebird.nl}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bio-logger.gemspec",
28
+ "lib/bio-logger.rb",
29
+ "lib/bio/log/logger.rb",
30
+ "lib/bio/log/loggercli.rb",
31
+ "lib/bio/log/loggersublevels.rb",
32
+ "lib/bio/log/loggerusers.rb",
33
+ "spec/biologger_cli_spec.rb",
34
+ "spec/biologger_spec.rb",
35
+ "test/helper.rb",
36
+ "test/test_bio-logger.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/pjotrp/bioruby-logger}
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Log4r wrapper for BioRuby}
43
+ s.test_files = [
44
+ "spec/biologger_cli_spec.rb",
45
+ "spec/biologger_spec.rb",
46
+ "test/helper.rb",
47
+ "test/test_bio-logger.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
58
+ 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
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ s.add_dependency(%q<bio>, [">= 1.4.1"])
67
+ s.add_dependency(%q<log4r>, ["> 1.1.6"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<shoulda>, [">= 0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ s.add_dependency(%q<bio>, [">= 1.4.1"])
75
+ s.add_dependency(%q<log4r>, ["> 1.1.6"])
76
+ end
77
+ end
78
+
@@ -0,0 +1,12 @@
1
+
2
+ require "rubygems"
3
+ begin
4
+ gem "log4r" , "> 1.1.8"
5
+ rescue
6
+ $stderr.print "log4r not installed, bailing out...\n"
7
+ exit 1
8
+ end
9
+
10
+ require 'log4r'
11
+ require 'bio/log/logger'
12
+ require 'bio/log/loggercli'
@@ -0,0 +1,60 @@
1
+
2
+ require 'bio/log/loggersublevels'
3
+ require 'bio/log/loggerusers'
4
+ require 'bio/log/loggercli'
5
+
6
+ module Bio
7
+
8
+ module Log
9
+
10
+ include Log4r
11
+
12
+ # Derived from the Log4r Logger class
13
+ class LoggerPlus < Logger
14
+ include LoggerSubLevels
15
+
16
+ def debug_ msg, options = {}
17
+ if options[:act]
18
+ options[:act].debug(self,msg)
19
+ else
20
+ debug msg
21
+ end
22
+ end
23
+
24
+ def info_ msg, options = {}
25
+ if options[:act]
26
+ options[:act].info(self,msg)
27
+ else
28
+ info msg
29
+ end
30
+ end
31
+
32
+ def warn_ msg, options = {}
33
+ if options[:act]
34
+ options[:act].warn(self,msg)
35
+ else
36
+ warn msg
37
+ end
38
+ end
39
+
40
+ def error_ msg, options = {}
41
+ if options[:act]
42
+ options[:act].error(self,msg)
43
+ else
44
+ error msg
45
+ end
46
+ end
47
+
48
+ def fatal_ msg, options = {}
49
+ if options[:act]
50
+ options[:act].fatal(self,msg)
51
+ else
52
+ fatal msg
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,95 @@
1
+ require 'singleton'
2
+
3
+ module Bio
4
+ module Log
5
+
6
+ class LoggerPlusGlobal
7
+ include Singleton
8
+
9
+ attr_accessor :outputter_type, :trace
10
+
11
+ end
12
+
13
+ module CLI
14
+
15
+ # Parse and store global logger type
16
+ def CLI::logger name
17
+ LoggerPlusGlobal.instance.outputter_type = case name
18
+ when 'stderr' then :stderr
19
+ when 'stdout' then :stdout
20
+ else
21
+ {:file => { :filename => name }}
22
+ end
23
+ end
24
+
25
+ # Parse and store trace options
26
+ def CLI::trace s
27
+ sub_level = nil
28
+
29
+ opts = {}
30
+ a = s.split(':')
31
+ if a.last =~ /^\d+$/
32
+ sub_level = a.pop.to_i
33
+ end
34
+ level = a.pop.downcase
35
+ outputter =
36
+ if a.size == 2
37
+ a.shift
38
+ end
39
+ if a.size == 0
40
+ a = [:default]
41
+ else
42
+ a = a[0].split(',')
43
+ end
44
+ a.each do | type |
45
+ opts[type] = { :level => level, :sub_level => sub_level }
46
+ opts[type][:outputter_name] = outputter if outputter
47
+ end
48
+ LoggerPlusGlobal.instance.trace ||= {}
49
+ LoggerPlusGlobal.instance.trace = LoggerPlusGlobal.instance.trace.merge(opts)
50
+ end
51
+
52
+ def CLI::configure logname = nil
53
+ include Bio::Log
54
+
55
+ type = LoggerPlusGlobal.instance.outputter_type
56
+ trace = LoggerPlusGlobal.instance.trace
57
+ trace ||= {}
58
+ default = {}
59
+ default = trace[:default] if trace[:default]
60
+ trace[logname] ||= {} if logname
61
+ trace.each do | name, opts |
62
+ next if name == :default
63
+ logger_type = type
64
+ logger_type = default[:outputter_name] if default[:outputter_name]
65
+ logger_type = opts[:outputter_name] if opts[:outputter_name]
66
+ logger = LoggerPlus[name]
67
+ raise "Unknown logger <#{name}>" if logger == nil
68
+ logger.outputters =
69
+ case logger_type
70
+ when 'stderr', :stderr then logger.outputters = Outputter.stderr
71
+ when nil, 'stdout', :stdout then logger.outputters = Outputter.stdout
72
+ else
73
+ # p [name, logger_type]
74
+ FileOutputter.new(name, logger_type[:file])
75
+ end
76
+ set_levels(logger, default) if default
77
+ set_levels(logger, opts)
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def CLI::set_levels logger, opts
84
+ logger.level = case opts[:level]
85
+ when 'debug' then DEBUG
86
+ when 'info' then INFO
87
+ when 'warn' then WARN
88
+ when 'error' then ERROR
89
+ when 'fatal' then FATAL
90
+ end if opts[:level]
91
+ logger.sub_level = opts[:sub_level] if opts[:sub_level]
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,153 @@
1
+
2
+ module Bio
3
+ module Log
4
+
5
+ # Support for numbered sub-levels. We could have used
6
+ # method_missing, or something similar, but this rather
7
+ # clean.
8
+ module LoggerSubLevels
9
+ attr_accessor :sub_level
10
+
11
+ def debug1(s)
12
+ debug(s) if !sub_level or sub_level >= 1
13
+ end
14
+ def debug2(s)
15
+ debug(s) if !sub_level or sub_level >= 2
16
+ end
17
+ def debug3(s)
18
+ debug(s) if !sub_level or sub_level >= 3
19
+ end
20
+ def debug4(s)
21
+ debug(s) if !sub_level or sub_level >= 4
22
+ end
23
+ def debug5(s)
24
+ debug(s) if !sub_level or sub_level >= 5
25
+ end
26
+ def debug6(s)
27
+ debug(s) if !sub_level or sub_level >= 6
28
+ end
29
+ def debug7(s)
30
+ debug(s) if !sub_level or sub_level >= 7
31
+ end
32
+ def debug8(s)
33
+ debug(s) if !sub_level or sub_level >= 8
34
+ end
35
+ def debug9(s)
36
+ debug(s) if !sub_level or sub_level >= 9
37
+ end
38
+
39
+ def info1(s)
40
+ info(s) if !sub_level or sub_level >= 1
41
+ end
42
+ def info2(s)
43
+ info(s) if !sub_level or sub_level >= 2
44
+ end
45
+ def info3(s)
46
+ info(s) if !sub_level or sub_level >= 3
47
+ end
48
+ def info4(s)
49
+ info(s) if !sub_level or sub_level >= 4
50
+ end
51
+ def info5(s)
52
+ info(s) if !sub_level or sub_level >= 5
53
+ end
54
+ def info6(s)
55
+ info(s) if !sub_level or sub_level >= 6
56
+ end
57
+ def info7(s)
58
+ info(s) if !sub_level or sub_level >= 7
59
+ end
60
+ def info8(s)
61
+ info(s) if !sub_level or sub_level >= 8
62
+ end
63
+ def info9(s)
64
+ info(s) if !sub_level or sub_level >= 9
65
+ end
66
+
67
+ def warn1(s)
68
+ warn(s) if !sub_level or sub_level >= 1
69
+ end
70
+ def warn2(s)
71
+ warn(s) if !sub_level or sub_level >= 2
72
+ end
73
+ def warn3(s)
74
+ warn(s) if !sub_level or sub_level >= 3
75
+ end
76
+ def warn4(s)
77
+ warn(s) if !sub_level or sub_level >= 4
78
+ end
79
+ def warn5(s)
80
+ warn(s) if !sub_level or sub_level >= 5
81
+ end
82
+ def warn6(s)
83
+ warn(s) if !sub_level or sub_level >= 6
84
+ end
85
+ def warn7(s)
86
+ warn(s) if !sub_level or sub_level >= 7
87
+ end
88
+ def warn8(s)
89
+ warn(s) if !sub_level or sub_level >= 8
90
+ end
91
+ def warn9(s)
92
+ warn(s) if !sub_level or sub_level >= 9
93
+ end
94
+
95
+ def error1(s)
96
+ error(s) if !sub_level or sub_level >= 1
97
+ end
98
+ def error2(s)
99
+ error(s) if !sub_level or sub_level >= 2
100
+ end
101
+ def error3(s)
102
+ error(s) if !sub_level or sub_level >= 3
103
+ end
104
+ def error4(s)
105
+ error(s) if !sub_level or sub_level >= 4
106
+ end
107
+ def error5(s)
108
+ error(s) if !sub_level or sub_level >= 5
109
+ end
110
+ def error6(s)
111
+ error(s) if !sub_level or sub_level >= 6
112
+ end
113
+ def error7(s)
114
+ error(s) if !sub_level or sub_level >= 7
115
+ end
116
+ def error8(s)
117
+ error(s) if !sub_level or sub_level >= 8
118
+ end
119
+ def error9(s)
120
+ error(s) if !sub_level or sub_level >= 9
121
+ end
122
+
123
+ def fatal1(s)
124
+ fatal(s) if !sub_level or sub_level >= 1
125
+ end
126
+ def fatal2(s)
127
+ fatal(s) if !sub_level or sub_level >= 2
128
+ end
129
+ def fatal3(s)
130
+ fatal(s) if !sub_level or sub_level >= 3
131
+ end
132
+ def fatal4(s)
133
+ fatal(s) if !sub_level or sub_level >= 4
134
+ end
135
+ def fatal5(s)
136
+ fatal(s) if !sub_level or sub_level >= 5
137
+ end
138
+ def fatal6(s)
139
+ fatal(s) if !sub_level or sub_level >= 6
140
+ end
141
+ def fatal7(s)
142
+ fatal(s) if !sub_level or sub_level >= 7
143
+ end
144
+ def fatal8(s)
145
+ fatal(s) if !sub_level or sub_level >= 8
146
+ end
147
+ def fatal9(s)
148
+ fatal(s) if !sub_level or sub_level >= 9
149
+ end
150
+
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,48 @@
1
+
2
+ module Bio
3
+
4
+ module Log
5
+
6
+ # NormalUser logs, but does not fail
7
+ class NormalUser
8
+ # include LoggerSubLevels
9
+
10
+ def debug logger,msg
11
+ logger.debug msg
12
+ end
13
+ def info logger,msg
14
+ logger.info msg
15
+ end
16
+ def warn logger,msg
17
+ logger.warn msg
18
+ end
19
+ def error logger,msg
20
+ logger.error msg
21
+ end
22
+ def fatal logger,msg
23
+ logger.fatal msg
24
+ end
25
+ end
26
+
27
+ class FailOnErrorException < RuntimeError
28
+ end
29
+
30
+ class FailOnError < NormalUser
31
+ def error logger, msg
32
+ logger.error msg
33
+ raise FailOnErrorException
34
+ end
35
+
36
+ def fatal logger, msg
37
+ logger.fatal msg
38
+ raise FailOnErrorException
39
+ end
40
+ end
41
+
42
+ # Developer acts so that errors raise an exception.
43
+ class Developer < FailOnError
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,78 @@
1
+ # RSpec for bio-logger plugin. Run with something like:
2
+ #
3
+ # rspec logger_spec.rb
4
+ #
5
+ # Copyright (C) 2011 Pjotr Prins <pjotr.prins@thebird.nl>
6
+ #
7
+
8
+ $: << "../lib"
9
+
10
+ require 'bio-logger'
11
+ include Bio::Log
12
+
13
+ describe Bio::Log::CLI, "bio-logger command line parsing" do
14
+
15
+ before(:all) do
16
+ # @mylog = Bio::Log::LoggerPlus.root
17
+ @mylog = LoggerPlus.new 'mylog'
18
+ @mylog.outputters = Outputter.stderr
19
+ @global = LoggerPlusGlobal.instance
20
+ end
21
+
22
+ before(:each) do
23
+ LoggerPlusGlobal.instance.trace = {}
24
+ LoggerPlusGlobal.instance.outputter_type = :stdout
25
+ end
26
+ it "should parse --logger stderr and set the global" do
27
+ CLI.logger("stderr")
28
+ LoggerPlusGlobal.instance.outputter_type.should == :stderr
29
+ end
30
+ it "should parse --logger filen to set filename logger" do
31
+ CLI.logger("test.log")
32
+ @global.outputter_type[:file].should == {:filename => 'test.log'}
33
+ end
34
+ it "should parse --trace debug to show all messages" do
35
+ CLI.trace("debug")
36
+ @global.trace[:default].should == { :level => 'debug', :sub_level => nil }
37
+ end
38
+ it "should parse --trace warn to show how messages more serious than 'warn'" do
39
+ CLI.trace("warn")
40
+ @global.trace[:default].should == { :level => 'warn', :sub_level => nil }
41
+ end
42
+ it "should parse --trace warn:3 to show messaged more serious that 'warn' level 3" do
43
+ CLI.trace("warn:3")
44
+ @global.trace[:default].should == { :level => 'warn', :sub_level => 3 }
45
+ end
46
+ it "should parse --trace blast:debug to override level for 'blast'" do
47
+ CLI.trace("blast:debug")
48
+ @global.trace.should == {"blast"=>{:level=>"debug", :sub_level=>nil}}
49
+ end
50
+ it "should parse --trace gff3:info:5 to override level for 'gff3' to info level 5" do
51
+ CLI.trace("gff3:info:5")
52
+ @global.trace.should == {"gff3"=>{:level=>"info", :sub_level=>5}}
53
+ end
54
+ it "should parse --trace blast,gff3:debug to override level for 'blast' and 'gff3'" do
55
+ CLI.trace("blast,gff3:debug:5")
56
+ @global.trace.should == {"blast"=>{:level=>"debug", :sub_level=>5}, "gff3"=>{:level=>"debug", :sub_level=>5}}
57
+ end
58
+ it "should parse --trace stderr:blast:debug to override level for 'blast' on stderr" do
59
+ CLI.trace("stderr:blast:debug")
60
+ @global.trace.should ==
61
+ {"blast"=>{:level=>"debug", :sub_level=>nil, :outputter_name=>"stderr"}}
62
+ end
63
+ it "should parse --trace stderr:blast,gff3:debug:1 to override level for 'blast' on stderr" do
64
+ CLI.trace("stderr:blast,gff3:debug:1")
65
+ @global.trace.should ==
66
+ {"blast"=>{:level=>"debug", :sub_level=>1, :outputter_name=>"stderr"}, "gff3"=>{:level=>"debug", :sub_level=>1, :outputter_name=>"stderr"}}
67
+ end
68
+ it "should realize setting warn:3" do
69
+ CLI.trace("blast:warn:3")
70
+ LoggerPlus.new('blast')
71
+ CLI.configure
72
+ log = LoggerPlus['blast']
73
+ log.level.should == WARN
74
+ log.sub_level.should == 3
75
+ end
76
+ end
77
+
78
+
@@ -0,0 +1,100 @@
1
+ # RSpec for bio-logger plugin. Run with something like:
2
+ #
3
+ # rspec logger_spec.rb
4
+ #
5
+ # Copyright (C) 2011 Pjotr Prins <pjotr.prins@thebird.nl>
6
+ #
7
+
8
+ $: << "../lib"
9
+
10
+ require 'bio-logger'
11
+ include Bio::Log
12
+
13
+ def logit mylog
14
+ mylog.debug "This is a message with level DEBUG"
15
+ mylog.info "This is a message with level INFO"
16
+ mylog.warn "This is a message with level WARN"
17
+ mylog.error "This is a message with level ERROR"
18
+ mylog.fatal "This is a message with level FATAL"
19
+ end
20
+
21
+
22
+ describe Bio::Log, "logs" do
23
+
24
+ before(:all) do
25
+ # @mylog = Bio::Log::LoggerPlus.root
26
+ @mylog = LoggerPlus.new 'mylog'
27
+ @mylog.outputters = Outputter.stderr
28
+ logit @mylog
29
+ blastlog = LoggerPlus.new 'blast'
30
+ blastlog.outputters = Outputter.stderr
31
+ end
32
+
33
+ after(:all) do
34
+ File.unlink("file.log")
35
+ File.unlink("TestSize000001.log")
36
+ end
37
+
38
+ it "should have a stderr logger" do
39
+ # logit @mylog
40
+ @mylog.info("This is a message with level INFO").should_not == nil
41
+ end
42
+
43
+ it "should have a rotating file logger" do
44
+ config = {
45
+ "filename" => "TestSize.log",
46
+ "maxsize" => 16000,
47
+ "trunc" => true
48
+ }
49
+ log2 = LoggerPlus.new 'mylog2'
50
+ log2.outputters = RollingFileOutputter.new("mylog2", config)
51
+ log2.info("This is a message with level INFO").should_not == nil
52
+ end
53
+ it "should have a file logger" do
54
+ log3 = LoggerPlus.new 'filelog'
55
+ log3.outputters = FileOutputter.new('filelog', :filename => 'file.log',:trunc => false)
56
+ log3.info("This is a message with level INFO").should_not == nil
57
+ File.read('file.log').should == " INFO filelog: This is a message with level INFO\n"
58
+ end
59
+ it "should set global loglevel to warn" do
60
+ # @mylog.level = Bio::Log::WARN
61
+ @mylog.level = WARN
62
+ # logit @mylog
63
+ @mylog.info("This is a message with level INFO").should == nil
64
+ @mylog.error("This is a message with level ERROR").should_not == nil
65
+ @mylog.level = DEBUG
66
+ end
67
+ it "should set global loglevel with WARN:3" do
68
+ @mylog.level = WARN
69
+ @mylog.sub_level = 3
70
+ @mylog.info("This is a message with level INFO").should == nil
71
+ @mylog.warn8("This is a message with level WARN:8").should == nil
72
+ @mylog.warn1("This is a message with level WARN:1").should_not == nil
73
+ @mylog.warn("This is a message with level WARN").should_not == nil
74
+ @mylog.error("This is a message with level ERROR").should_not == nil
75
+ @mylog.level = DEBUG
76
+ @mylog.sub_level = nil
77
+ @mylog.info("This is a message with level INFO").should_not == nil
78
+ @mylog.warn8("This is a message with level WARN:8").should_not == nil
79
+ end
80
+ it "should override level for 'blast' to info level 5" do
81
+ log = LoggerPlus['blast']
82
+ log.should_not == nil
83
+ log.info("This is a message with level INFO").should_not == nil
84
+ log.level = INFO
85
+ log.sub_level = 5
86
+ log.info("This is a message with level INFO").should_not == nil
87
+ log.info5("This is a message with level INFO:5").should_not == nil
88
+ log.info6("This is a message with level INFO:6").should == nil
89
+ end
90
+ it "should modify the logger for development" do
91
+ @mylog.error_("ERROR should not fail",:act => NormalUser.new).should_not == nil
92
+ dev = Developer.new
93
+ @mylog.info_("INFO should not fail",:act => dev).should_not == nil
94
+ lambda { @mylog.error_("As Developer ERROR should fail",:act => dev) }.should raise_error
95
+ lambda { @mylog.fatal_("As Developer FATAL should fail",:act => dev) }.should raise_error
96
+
97
+ end
98
+ end
99
+
100
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'bio-logger'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
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
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bio-logger
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
10
+ platform: ruby
11
+ authors:
12
+ - Pjotr Prins
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-12 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 0
43
+ - 0
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 5
58
+ - 2
59
+ version: 1.5.2
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rcov
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: bio
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 1
85
+ - 4
86
+ - 1
87
+ version: 1.4.1
88
+ type: :development
89
+ prerelease: false
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
+ description: Log4r wrapper for BioRuby
107
+ email: pjotr.public01@thebird.nl
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files:
113
+ - LICENSE.txt
114
+ - README.rdoc
115
+ files:
116
+ - .document
117
+ - Gemfile
118
+ - Gemfile.lock
119
+ - LICENSE.txt
120
+ - README.rdoc
121
+ - Rakefile
122
+ - VERSION
123
+ - bio-logger.gemspec
124
+ - lib/bio-logger.rb
125
+ - lib/bio/log/logger.rb
126
+ - lib/bio/log/loggercli.rb
127
+ - lib/bio/log/loggersublevels.rb
128
+ - lib/bio/log/loggerusers.rb
129
+ - spec/biologger_cli_spec.rb
130
+ - spec/biologger_spec.rb
131
+ - test/helper.rb
132
+ - test/test_bio-logger.rb
133
+ has_rdoc: true
134
+ homepage: http://github.com/pjotrp/bioruby-logger
135
+ licenses:
136
+ - MIT
137
+ post_install_message:
138
+ rdoc_options: []
139
+
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: -784249939
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.3.7
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Log4r wrapper for BioRuby
166
+ test_files:
167
+ - spec/biologger_cli_spec.rb
168
+ - spec/biologger_spec.rb
169
+ - test/helper.rb
170
+ - test/test_bio-logger.rb