log4r 1.1.9 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,9 @@
1
- $: << File.join("..","lib")
2
- require "test/unit"
3
- require "log4r"
4
- include Log4r
1
+ # encoding: utf-8
2
+ require 'test_helper'
5
3
 
4
+ class TestOutputter < TestCase
5
+ include Log4r
6
6
 
7
- class TestOutputter < Test::Unit::TestCase
8
7
  def test_validation
9
8
  assert_raise(ArgumentError) { Outputter.new }
10
9
  assert_raise(ArgumentError) { Outputter.new 'fonda', :level=>-10}
@@ -55,13 +54,13 @@ class TestOutputter < Test::Unit::TestCase
55
54
  assert_raise(TypeError) { o.formatter = "bogus" }
56
55
  assert_raise(TypeError) { o.formatter = -3 }
57
56
  # the formatter should be preserved
58
- assert(o.formatter.class == Formatter)
57
+ assert(o.formatter.class == Formatter)
59
58
  end
60
59
  def test_file
61
60
  assert_raise(TypeError) { FileOutputter.new 'f' }
62
61
  assert_raise(TypeError) { FileOutputter.new('fa', :filename => DEBUG) }
63
62
  assert_raise(TypeError) { FileOutputter.new('fo', :filename => nil) }
64
- assert_nothing_raised {
63
+ assert_nothing_raised {
65
64
  FileOutputter.new('fi', :filename => './junk/tmp')
66
65
  FileOutputter.new('fum', :filename=>'./junk/tmp', :trunc => "true")
67
66
  }
@@ -80,11 +79,11 @@ class TestOutputter < Test::Unit::TestCase
80
79
  for mname in LNAMES
81
80
  next if mname == 'OFF' || mname == 'ALL'
82
81
  assert_respond_to(o, mname.downcase.to_sym, "Test respond to #{mname.to_s}")
83
- end
82
+ end
84
83
  return # cuz the rest is borked
85
84
  # we rely on BasicFormatter's inability to reference a nil Logger to test
86
85
  # the log methods. Everything from WARN to FATAL should choke.
87
- event = LogEvent.new(nil, nil, nil, nil)
86
+ event = LogEvent.new(nil, nil, nil, nil)
88
87
  assert_nothing_raised { o.debug event }
89
88
  assert_nothing_raised { o.info event }
90
89
  assert_raise(NameError) { o.warn event }
@@ -94,7 +93,7 @@ class TestOutputter < Test::Unit::TestCase
94
93
  o.level = ERROR
95
94
  assert_nothing_raised { o.debug event}
96
95
  assert_nothing_raised { o.info event}
97
- assert_nothing_raised { o.warn event}
96
+ assert_nothing_raised { o.warn event}
98
97
  assert_raise(NameError) { o.error event}
99
98
  assert_raise(NameError) { o.fatal event}
100
99
  end
@@ -113,6 +112,18 @@ class TestOutputter < Test::Unit::TestCase
113
112
  assert_nothing_raised { o.info event}
114
113
  assert_nothing_raised { o.fatal event}
115
114
  end
115
+ if defined?( Encoding )
116
+ # tests that files are opened in binary mode
117
+ def test_file_encoding
118
+ Encoding.default_internal = Encoding::UTF_8
119
+ File.open( './junk/tmp2', 'w' ) { |f| f.write( 'scheiß encoding' ) }
120
+ fenc = FileOutputter.new('fenc', :filename => './junk/tmp2')
121
+ event = LogEvent.new(1, Logger.root, nil, 'scheiß encoding'.force_encoding('ASCII-8BIT'))
122
+ assert_nothing_raised(Encoding::UndefinedConversionError) do
123
+ fenc.debug event
124
+ end
125
+ end
126
+ end
116
127
  def broken_test_threading
117
128
  class << self
118
129
  def log_work
@@ -129,4 +140,4 @@ class TestOutputter < Test::Unit::TestCase
129
140
  ts = Thread.new(log_thread_start)
130
141
  ts.join
131
142
  end
132
- end
143
+ end
@@ -1,16 +1,14 @@
1
- $: << File.join("..","lib")
2
- require "test/unit"
3
- require "log4r"
4
- include Log4r
1
+ require 'test_helper'
5
2
 
3
+ class TestPatternFormatter < TestCase
4
+ include Log4r
6
5
 
7
- class TestPatternFormatter < Test::Unit::TestCase
8
6
  def test_pattern
9
7
  l = Logger.new 'test::this::that'
10
8
  l.trace = true
11
- o = StdoutOutputter.new 'test'
9
+ o = StdoutOutputter.new 'test'
12
10
  l.add o
13
- assert_nothing_raised {
11
+ assert_nothing_raised {
14
12
  f = PatternFormatter.new :pattern=> "'%t' T-'%T' %d %6l [%C]%c %% %-40.30M"
15
13
  #:date_pattern=> "%Y"
16
14
  #:date_method => :usec
@@ -28,7 +26,7 @@ class TestPatternFormatter < Test::Unit::TestCase
28
26
  def test_ndc
29
27
  l = Logger.new 'test::this::that::other'
30
28
  l.trace = true
31
- o = StdoutOutputter.new 'testy'
29
+ o = StdoutOutputter.new 'testy'
32
30
  l.add o
33
31
  f = PatternFormatter.new :pattern=> "%d %6l [%C]%c {%x} %% %-40.30M"
34
32
  #:date_pattern=> "%Y"
@@ -49,7 +47,7 @@ class TestPatternFormatter < Test::Unit::TestCase
49
47
  def test_gdc
50
48
  l = Logger.new 'test::this::that::other'
51
49
  l.trace = true
52
- o = StdoutOutputter.new 'testy'
50
+ o = StdoutOutputter.new 'testy'
53
51
  l.add o
54
52
  f = PatternFormatter.new :pattern=> "%d %6l [%C]%c {%g} %% %-40.30M"
55
53
  #:date_pattern=> "%Y"
@@ -64,7 +62,7 @@ class TestPatternFormatter < Test::Unit::TestCase
64
62
  def test_mdc
65
63
  l = Logger.new 'test::this::that::other'
66
64
  l.trace = true
67
- o = StdoutOutputter.new 'testy'
65
+ o = StdoutOutputter.new 'testy'
68
66
  l.add o
69
67
  f = PatternFormatter.new :pattern=> "%d %6l [%C]%c {%X{user}} %% %-40.30M"
70
68
  #:date_pattern=> "%Y"
@@ -1,6 +1,6 @@
1
1
  # $Id$
2
2
  # Test guts sent in by chetreddy bug #27184
3
- #
3
+ #
4
4
  # Note: this test won't always catch a threading problem, as it
5
5
  # relies on a brute force approach. NUM_THREADS can be increased
6
6
  # to stress the system longer and therefore increasing the chance
@@ -8,14 +8,10 @@
8
8
  # test.
9
9
  #
10
10
 
11
+ require 'test_helper'
11
12
 
12
- $: << File.join("..","lib")
13
-
14
- require "test/unit"
15
- require 'log4r'
16
- include Log4r
17
-
18
- class TestThreads < Test::Unit::TestCase
13
+ class TestThreads < TestCase
14
+ include Log4r
19
15
 
20
16
  NUMTHREADS = 1000
21
17
 
@@ -24,11 +20,11 @@ class TestThreads < Test::Unit::TestCase
24
20
  assert_nothing_raised do
25
21
  (0..NUMTHREADS).map do |i|
26
22
  Thread.new do
27
- Thread.current[:logger] = Log4r::Logger.new "Hello #{i}"
28
- Thread.current[:logger].outputters = [StdoutOutputter.new "log4r#{i}"]
29
- Thread.current[:logger].outputters.each { |i| i.flush }
30
- Thread.current.exit()
31
- end
23
+ Thread.current[:logger] = Log4r::Logger.new "Hello #{i}"
24
+ Thread.current[:logger].outputters = [StdoutOutputter.new("log4r#{i}")]
25
+ Thread.current[:logger].outputters.each { |j| j.flush }
26
+ Thread.current.exit()
27
+ end
32
28
  end.each do |thr| thr.join end
33
29
  end
34
30
  end
@@ -1,3 +1,4 @@
1
+ require 'test_helper'
1
2
 
2
3
  One=<<-EOX
3
4
  <log4r_config><pre_config><custom_levels> Foo </custom_levels>
@@ -14,28 +15,30 @@ EOX
14
15
 
15
16
  # must be run independently
16
17
  class TestXmlConf < TestCase
18
+ include Log4r
19
+
17
20
  def test_load1
18
21
  Configurator.load_xml_string(One)
19
- assert_no_exception{
22
+ assert_nothing_raised{
20
23
  assert(Foo == 1)
21
24
  assert(Logger.global.level == ALL)
22
25
  }
23
26
  end
24
27
  def test_load2
25
28
  Configurator.load_xml_string(Two)
26
- assert_no_exception{
29
+ assert_nothing_raised{
27
30
  assert(Logger.global.level == DEBUG)
28
31
  }
29
32
  end
30
33
  def test_load3
31
34
  Configurator.load_xml_string(Three)
32
- assert_no_exception{
35
+ assert_nothing_raised{
33
36
  assert(Foo == 1)
34
37
  assert(Logger.global.level == Foo)
35
38
  }
36
39
  end
37
40
  def test_load4
38
- assert_no_exception {
41
+ assert_nothing_raised {
39
42
  Configurator['logpath'] = '.'
40
43
  Configurator.load_xml_file "xml/testconf.xml"
41
44
  a = Logger['first::second']
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ # Define a custom outputter that allows arrays in configuration hash
4
+ module Log4r
5
+ class TestYamlOutputter < Outputter
6
+ # expose array parameter
7
+ attr_reader :array_param
8
+
9
+ def initialize(name, hash = {})
10
+ @array_param = hash['array_param']
11
+ end
12
+ end
13
+ end
14
+
15
+
16
+ class TestYaml < TestCase
17
+ include Log4r
18
+
19
+ def setup
20
+ @cfg = YamlConfigurator # shorthand
21
+ @cfg['CUSTOM_DOMAIN'] = 'bar.com'
22
+ end
23
+
24
+ def test_injection
25
+ assert_nothing_raised("Exception injected") do
26
+ @cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_injection.yaml'))
27
+ end
28
+ end
29
+
30
+ def test_arrays
31
+ assert_nothing_raised("Parser couldn't handle arrays in YAML") do
32
+ @cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_arrays.yaml'))
33
+ end
34
+ log = Logger['mylogger']
35
+ assert_instance_of(Array, log.outputters.first.array_param, 'Array not loaded properly from YAML')
36
+ assert_equal('wilma@bar.com', log.outputters.first.array_param[2], '#{}-style parameter interpolation doesn\'t work properly in arrays')
37
+ end
38
+ end
39
+
@@ -0,0 +1,25 @@
1
+ log4r_config:
2
+
3
+ # define all loggers ...
4
+ loggers:
5
+ - name : mylogger
6
+ level : INFO
7
+ additive : 'false'
8
+ trace : 'false'
9
+ outputters:
10
+ - testyaml
11
+
12
+ # define all outputters (incl. formatters)
13
+ outputters:
14
+ - type : TestYamlOutputter
15
+ name : testyaml
16
+ level : INFO
17
+ array_param:
18
+ - fred@foo.com
19
+ - barney@foo.com
20
+ - 'wilma@#{CUSTOM_DOMAIN}'
21
+ formatter:
22
+ date_pattern: '%y%m%d %H:%M:%S'
23
+ pattern : '%d %l: %m '
24
+ type : PatternFormatter
25
+
@@ -0,0 +1,22 @@
1
+ log4r_config:
2
+
3
+ # define all loggers ...
4
+ loggers:
5
+ - name : mylogger
6
+ level : INFO
7
+ additive : 'false'
8
+ trace : 'false'
9
+ outputters:
10
+ - stderr
11
+
12
+ # define all outputters (incl. formatters)
13
+ outputters:
14
+ - type : StderrOutputter
15
+ name : stderr
16
+ level : INFO
17
+ crash : "'; raise Exception #"
18
+ formatter:
19
+ date_pattern: '%y%m%d %H:%M:%S'
20
+ pattern : '%d %l: %m '
21
+ type : PatternFormatter
22
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log4r
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 9
10
- version: 1.1.9
9
+ - 10
10
+ version: 1.1.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Colby Gutierrez-Kraybill
@@ -15,27 +15,49 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-28 00:00:00 -07:00
19
- default_executable:
20
- dependencies: []
21
-
18
+ date: 2012-01-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ version: 1.0.0
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 49
45
+ segments:
46
+ - 0
47
+ - 8
48
+ - 7
49
+ version: 0.8.7
50
+ type: :development
51
+ version_requirements: *id002
22
52
  description: "See also: http://logging.apache.org/log4j"
23
53
  email: colby@astro.berkeley.edu
24
54
  executables: []
25
55
 
26
56
  extensions: []
27
57
 
28
- extra_rdoc_files:
29
- - README
30
- - LICENSE
31
- - TODO
58
+ extra_rdoc_files: []
59
+
32
60
  files:
33
- - LICENSE
34
- - LICENSE.LGPLv3
35
- - README
36
- - INSTALL
37
- - Rakefile
38
- - TODO
39
61
  - doc/content/contact.html
40
62
  - doc/content/contribute.html
41
63
  - doc/content/index.html
@@ -95,6 +117,7 @@ files:
95
117
  - lib/log4r/outputter/outputterfactory.rb
96
118
  - lib/log4r/outputter/remoteoutputter.rb
97
119
  - lib/log4r/outputter/rollingfileoutputter.rb
120
+ - lib/log4r/outputter/scribeoutputter.rb
98
121
  - lib/log4r/outputter/staticoutputter.rb
99
122
  - lib/log4r/outputter/syslogoutputter.rb
100
123
  - lib/log4r/outputter/udpoutputter.rb
@@ -102,6 +125,7 @@ files:
102
125
  - lib/log4r/rdoc/emailoutputter
103
126
  - lib/log4r/rdoc/formatter
104
127
  - lib/log4r/rdoc/GDC
128
+ - lib/log4r/rdoc/log4jxmlformatter
105
129
  - lib/log4r/rdoc/log4r
106
130
  - lib/log4r/rdoc/logger
107
131
  - lib/log4r/rdoc/logserver
@@ -109,14 +133,17 @@ files:
109
133
  - lib/log4r/rdoc/NDC
110
134
  - lib/log4r/rdoc/outputter
111
135
  - lib/log4r/rdoc/patternformatter
136
+ - lib/log4r/rdoc/scribeoutputter
112
137
  - lib/log4r/rdoc/syslogoutputter
113
138
  - lib/log4r/rdoc/win32eventoutputter
114
139
  - lib/log4r/rdoc/yamlconfigurator
115
140
  - lib/log4r/repository.rb
116
141
  - lib/log4r/staticlogger.rb
142
+ - lib/log4r/version.rb
117
143
  - lib/log4r/yamlconfigurator.rb
118
144
  - lib/log4r.rb
119
145
  - tests/README
146
+ - tests/test_helper.rb
120
147
  - tests/testall.rb
121
148
  - tests/testbase.rb
122
149
  - tests/testchainsaw.rb
@@ -131,7 +158,9 @@ files:
131
158
  - tests/testpatternformatter.rb
132
159
  - tests/testthreads.rb
133
160
  - tests/testxmlconf.rb
134
- has_rdoc: true
161
+ - tests/testyaml.rb
162
+ - tests/testyaml_arrays.yaml
163
+ - tests/testyaml_injection.yaml
135
164
  homepage: http://log4r.rubyforge.org
136
165
  licenses: []
137
166
 
@@ -160,10 +189,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
189
  version: "0"
161
190
  requirements: []
162
191
 
163
- rubyforge_project: log4r
164
- rubygems_version: 1.3.7
192
+ rubyforge_project:
193
+ rubygems_version: 1.8.8
165
194
  signing_key:
166
195
  specification_version: 3
167
196
  summary: Log4r, logging framework for ruby
168
- test_files: []
169
-
197
+ test_files:
198
+ - tests/README
199
+ - tests/test_helper.rb
200
+ - tests/testall.rb
201
+ - tests/testbase.rb
202
+ - tests/testchainsaw.rb
203
+ - tests/testconf.xml
204
+ - tests/testcustom.rb
205
+ - tests/testformatter.rb
206
+ - tests/testGDC.rb
207
+ - tests/testlogger.rb
208
+ - tests/testMDC.rb
209
+ - tests/testNDC.rb
210
+ - tests/testoutputter.rb
211
+ - tests/testpatternformatter.rb
212
+ - tests/testthreads.rb
213
+ - tests/testxmlconf.rb
214
+ - tests/testyaml.rb
215
+ - tests/testyaml_arrays.yaml
216
+ - tests/testyaml_injection.yaml