logging 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.9.8 / 2009-04-11
2
+
3
+ 2 minor enhancements
4
+ - Adding a to_s method to the StringIo appender's StringIO object
5
+ - Added a Spec::LoggingHelper class that will capture log messages
6
+ when using rspec style testing
7
+
1
8
  == 0.9.7 / 2009-03-17
2
9
 
3
10
  1 minor enhancement
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ PROJ.version = Logging::VERSION
25
25
  PROJ.readme_file = 'README.rdoc'
26
26
  PROJ.ignore_file = '.gitignore'
27
27
 
28
- PROJ.exclude << %w[^tags$]
28
+ PROJ.exclude << %w[^tags$ logging.gemspec]
29
29
  PROJ.rdoc.exclude << '^data'
30
30
  #PROJ.rdoc.dir = 'doc/rdoc'
31
31
  #PROJ.rdoc.remote_dir = 'rdoc'
data/lib/logging.rb CHANGED
@@ -13,7 +13,7 @@ begin require 'fastthread'; rescue LoadError; end
13
13
  module Logging
14
14
 
15
15
  # :stopdoc:
16
- VERSION = '0.9.7'
16
+ VERSION = '0.9.8'
17
17
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
18
18
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
19
19
  WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM
@@ -394,6 +394,7 @@ Logging.require_all_libs_relative_to(__FILE__, 'logging/config')
394
394
  # or e-mail servers, etc.
395
395
  #
396
396
  at_exit {
397
+ Logging.log_internal {'at_exit hook called - closing all appenders'}
397
398
  Logging::Appender.instance_variable_get(:@appenders).values.each do |ap|
398
399
  ap.close
399
400
  end
@@ -19,26 +19,11 @@ module Logging::Appenders
19
19
  #
20
20
  def initialize( name, opts = {} )
21
21
  @sio = StringIO.new
22
+ @sio.extend IoToS
22
23
  super(name, @sio, opts)
23
24
  clear
24
25
  end
25
26
 
26
- # Read a single line of text from the internal StringIO instance. +nil+
27
- # is returned if the StringIO buffer is empty.
28
- #
29
- def readline
30
- sync {
31
- begin
32
- @sio.seek @pos
33
- line = @sio.readline
34
- @pos = @sio.tell
35
- line
36
- rescue EOFError
37
- nil
38
- end
39
- }
40
- end
41
-
42
27
  # Clears the internal StringIO instance. All log messages are removed
43
28
  # from the buffer.
44
29
  #
@@ -51,6 +36,34 @@ module Logging::Appenders
51
36
  end
52
37
  alias :reset :clear
53
38
 
39
+ %w[read readline readlines].each do|m|
40
+ class_eval <<-CODE
41
+ def #{m}( *args )
42
+ sync {
43
+ begin
44
+ @sio.seek @pos
45
+ rv = @sio.#{m}(*args)
46
+ @pos = @sio.tell
47
+ rv
48
+ rescue EOFError
49
+ nil
50
+ end
51
+ }
52
+ end
53
+ CODE
54
+ end
55
+
56
+ # :stopdoc:
57
+ module IoToS
58
+ def to_s
59
+ seek 0
60
+ str = read
61
+ seek 0
62
+ return str
63
+ end
64
+ end
65
+ # :startdoc:
66
+
54
67
  end # class StringIo
55
68
  end # module Logging::Appenders
56
69
 
@@ -82,7 +82,7 @@ module Logging::Config
82
82
  l.additive = config[:additive] if l.respond_to? :additive=
83
83
  l.trace = config[:trace]
84
84
  l.appenders = Array(config[:appenders]).
85
- map {|name| ::Logging::Appender[name]}
85
+ map {|nm| ::Logging::Appender[nm]}
86
86
  end
87
87
  end
88
88
 
@@ -0,0 +1,34 @@
1
+
2
+ module Spec
3
+ module LoggingHelper
4
+
5
+ # Capture log messages from the Logging framework and make them
6
+ # available via a @log_output instance variable. The @log_output
7
+ # supports a readline method to access the log messags.
8
+ #
9
+ def capture_log_messages( opts = {} )
10
+ from = opts.getopt(:from, 'root')
11
+ to = opts.getopt(:to, '__rspec__')
12
+ exclusive = opts.getopt(:exclusive, true)
13
+
14
+ appender = Logging::Appender[to] || Logging::Appenders::StringIo.new(to)
15
+ logger = Logging::Logger[from]
16
+ if exclusive
17
+ logger.appenders = appender
18
+ else
19
+ logger.add_appenders(appender)
20
+ end
21
+
22
+ before(:all) do
23
+ @log_output = Logging::Appender[to]
24
+ end
25
+
26
+ before(:each) do
27
+ @log_output.reset
28
+ end
29
+ end
30
+
31
+ end # module LoggingHelper
32
+ end # module Spec
33
+
34
+ # EOF
data/tasks/setup.rb CHANGED
@@ -147,7 +147,7 @@ RCOV = "#{RUBY} -S rcov"
147
147
  RDOC = "#{RUBY} -S rdoc"
148
148
  GEM = "#{RUBY} -S gem"
149
149
 
150
- %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
150
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode zentest).each do |lib|
151
151
  begin
152
152
  require lib
153
153
  Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
@@ -0,0 +1,36 @@
1
+ if HAVE_ZENTEST
2
+
3
+ # --------------------------------------------------------------------------
4
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
5
+ require 'autotest'
6
+
7
+ namespace :test do
8
+ task :autotest do
9
+ Autotest.run
10
+ end
11
+ end
12
+
13
+ desc "Run the autotest loop"
14
+ task :autotest => 'test:autotest'
15
+
16
+ end # if test
17
+
18
+ # --------------------------------------------------------------------------
19
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
20
+ require 'autotest/rspec'
21
+
22
+ namespace :spec do
23
+ task :autotest do
24
+ load '.autotest' if test(?f, '.autotest')
25
+ Autotest::Rspec.run
26
+ end
27
+ end
28
+
29
+ desc "Run the autotest loop"
30
+ task :autotest => 'spec:autotest'
31
+
32
+ end # if rspec
33
+
34
+ end # if HAVE_ZENTEST
35
+
36
+ # EOF
data/test/test_logger.rb CHANGED
@@ -645,6 +645,7 @@ module TestLogging
645
645
  log_d = ::Logging::Logger['A-logger::D-logger']
646
646
 
647
647
  sio = StringIO.new
648
+ sio.extend ::Logging::Appenders::StringIo::IoToS
648
649
 
649
650
  log_a._dump_configuration( sio )
650
651
  assert_equal(
@@ -699,13 +700,4 @@ module TestLogging
699
700
  end # class TestLogger
700
701
  end # module TestLogging
701
702
 
702
- class StringIO
703
- def to_s
704
- seek 0
705
- str = read
706
- seek 0
707
- return str
708
- end
709
- end
710
-
711
703
  # EOF
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-17 00:00:00 -06:00
12
+ date: 2009-04-15 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 2.4.2
43
+ version: 2.5.0
44
44
  version:
45
45
  description: Logging is a flexible logging library for use in Ruby programs based on the design of Java's log4j library. It features a hierarchical logging system, custom level names, multiple output destinations per log event, custom formatting, and more.
46
46
  email: tim.pease@gmail.com
@@ -82,7 +82,7 @@ files:
82
82
  - lib/logging/root_logger.rb
83
83
  - lib/logging/stats.rb
84
84
  - lib/logging/utils.rb
85
- - logging.gemspec
85
+ - lib/spec/logging_helper.rb
86
86
  - tasks/ann.rake
87
87
  - tasks/bones.rake
88
88
  - tasks/gem.rake
@@ -95,6 +95,7 @@ files:
95
95
  - tasks/spec.rake
96
96
  - tasks/svn.rake
97
97
  - tasks/test.rake
98
+ - tasks/zentest.rake
98
99
  - test/appenders/test_buffered_io.rb
99
100
  - test/appenders/test_console.rb
100
101
  - test/appenders/test_email.rb
data/logging.gemspec DELETED
@@ -1,41 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{logging}
5
- s.version = "0.9.7"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Tim Pease"]
9
- s.date = %q{2009-03-17}
10
- s.description = %q{Logging is a flexible logging library for use in Ruby programs based on the design of Java's log4j library. It features a hierarchical logging system, custom level names, multiple output destinations per log event, custom formatting, and more.}
11
- s.email = %q{tim.pease@gmail.com}
12
- s.extra_rdoc_files = ["History.txt", "README.rdoc"]
13
- s.files = ["History.txt", "README.rdoc", "Rakefile", "data/bad_logging_1.rb", "data/bad_logging_2.rb", "data/logging.rb", "data/logging.yaml", "data/simple_logging.rb", "lib/logging.rb", "lib/logging/appender.rb", "lib/logging/appenders/buffering.rb", "lib/logging/appenders/console.rb", "lib/logging/appenders/email.rb", "lib/logging/appenders/file.rb", "lib/logging/appenders/growl.rb", "lib/logging/appenders/io.rb", "lib/logging/appenders/rolling_file.rb", "lib/logging/appenders/string_io.rb", "lib/logging/appenders/syslog.rb", "lib/logging/config/configurator.rb", "lib/logging/config/yaml_configurator.rb", "lib/logging/layout.rb", "lib/logging/layouts/basic.rb", "lib/logging/layouts/pattern.rb", "lib/logging/log_event.rb", "lib/logging/logger.rb", "lib/logging/repository.rb", "lib/logging/root_logger.rb", "lib/logging/stats.rb", "lib/logging/utils.rb", "logging.gemspec", "test/appenders/test_buffered_io.rb", "test/appenders/test_console.rb", "test/appenders/test_email.rb", "test/appenders/test_file.rb", "test/appenders/test_growl.rb", "test/appenders/test_io.rb", "test/appenders/test_rolling_file.rb", "test/appenders/test_syslog.rb", "test/benchmark.rb", "test/config/test_configurator.rb", "test/config/test_yaml_configurator.rb", "test/layouts/test_basic.rb", "test/layouts/test_pattern.rb", "test/setup.rb", "test/test_appender.rb", "test/test_layout.rb", "test/test_log_event.rb", "test/test_logger.rb", "test/test_logging.rb", "test/test_repository.rb", "test/test_root_logger.rb", "test/test_stats.rb", "test/test_utils.rb"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://logging.rubyforge.org/}
16
- s.rdoc_options = ["--main", "README.rdoc"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{logging}
19
- s.rubygems_version = %q{1.3.1}
20
- s.summary = %q{A flexible and extendable logging library for Ruby}
21
- s.test_files = ["test/appenders/test_buffered_io.rb", "test/appenders/test_console.rb", "test/appenders/test_email.rb", "test/appenders/test_file.rb", "test/appenders/test_growl.rb", "test/appenders/test_io.rb", "test/appenders/test_rolling_file.rb", "test/appenders/test_syslog.rb", "test/config/test_configurator.rb", "test/config/test_yaml_configurator.rb", "test/layouts/test_basic.rb", "test/layouts/test_pattern.rb", "test/test_appender.rb", "test/test_layout.rb", "test/test_log_event.rb", "test/test_logger.rb", "test/test_logging.rb", "test/test_repository.rb", "test/test_root_logger.rb", "test/test_stats.rb", "test/test_utils.rb"]
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<flexmock>, [">= 0.8.2"])
29
- s.add_runtime_dependency(%q<lockfile>, [">= 1.4.3"])
30
- s.add_development_dependency(%q<bones>, [">= 2.4.2"])
31
- else
32
- s.add_dependency(%q<flexmock>, [">= 0.8.2"])
33
- s.add_dependency(%q<lockfile>, [">= 1.4.3"])
34
- s.add_dependency(%q<bones>, [">= 2.4.2"])
35
- end
36
- else
37
- s.add_dependency(%q<flexmock>, [">= 0.8.2"])
38
- s.add_dependency(%q<lockfile>, [">= 1.4.3"])
39
- s.add_dependency(%q<bones>, [">= 2.4.2"])
40
- end
41
- end