log4r-color 1.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL +11 -0
- data/LICENSE +90 -0
- data/LICENSE.LGPLv3 +165 -0
- data/README +95 -0
- data/Rakefile +80 -0
- data/TODO +2 -0
- data/doc/content/contact.html +22 -0
- data/doc/content/contribute.html +21 -0
- data/doc/content/index.html +90 -0
- data/doc/content/license.html +56 -0
- data/doc/content/manual.html +449 -0
- data/doc/dev/README.developers +55 -0
- data/doc/dev/checklist +23 -0
- data/doc/dev/things-to-do +5 -0
- data/doc/images/log4r-logo.png +0 -0
- data/doc/images/logo2.png +0 -0
- data/doc/log4r.css +111 -0
- data/doc/rdoc-log4r.css +696 -0
- data/doc/templates/main.html +147 -0
- data/examples/README +19 -0
- data/examples/ancestors.rb +53 -0
- data/examples/chainsaw_settings.xml +7 -0
- data/examples/color_output.rb +26 -0
- data/examples/customlevels.rb +34 -0
- data/examples/filelog.rb +25 -0
- data/examples/fileroll.rb +40 -0
- data/examples/gmail.rb +30 -0
- data/examples/gmail.yaml +95 -0
- data/examples/log4r_yaml.yaml +0 -0
- data/examples/logclient.rb +25 -0
- data/examples/logserver.rb +18 -0
- data/examples/moderate.xml +29 -0
- data/examples/moderateconfig.rb +66 -0
- data/examples/myformatter.rb +23 -0
- data/examples/outofthebox.rb +21 -0
- data/examples/rdoc-gen +2 -0
- data/examples/rrconfig.xml +63 -0
- data/examples/rrsetup.rb +42 -0
- data/examples/simpleconfig.rb +39 -0
- data/examples/syslogcustom.rb +52 -0
- data/examples/xmlconfig.rb +25 -0
- data/examples/yaml.rb +30 -0
- data/lib/log4r.rb +20 -0
- data/lib/log4r/GDC.rb +41 -0
- data/lib/log4r/MDC.rb +59 -0
- data/lib/log4r/NDC.rb +86 -0
- data/lib/log4r/base.rb +90 -0
- data/lib/log4r/config.rb +9 -0
- data/lib/log4r/configurator.rb +224 -0
- data/lib/log4r/formatter/formatter.rb +105 -0
- data/lib/log4r/formatter/log4jxmlformatter.rb +61 -0
- data/lib/log4r/formatter/patternformatter.rb +145 -0
- data/lib/log4r/lib/drbloader.rb +52 -0
- data/lib/log4r/lib/xmlloader.rb +24 -0
- data/lib/log4r/logevent.rb +28 -0
- data/lib/log4r/logger.rb +199 -0
- data/lib/log4r/loggerfactory.rb +89 -0
- data/lib/log4r/logserver.rb +28 -0
- data/lib/log4r/outputter/consoleoutputters.rb +49 -0
- data/lib/log4r/outputter/datefileoutputter.rb +117 -0
- data/lib/log4r/outputter/emailoutputter.rb +143 -0
- data/lib/log4r/outputter/fileoutputter.rb +56 -0
- data/lib/log4r/outputter/iooutputter.rb +55 -0
- data/lib/log4r/outputter/outputter.rb +146 -0
- data/lib/log4r/outputter/outputterfactory.rb +61 -0
- data/lib/log4r/outputter/remoteoutputter.rb +40 -0
- data/lib/log4r/outputter/rollingfileoutputter.rb +234 -0
- data/lib/log4r/outputter/scribeoutputter.rb +37 -0
- data/lib/log4r/outputter/staticoutputter.rb +32 -0
- data/lib/log4r/outputter/syslogoutputter.rb +130 -0
- data/lib/log4r/outputter/udpoutputter.rb +53 -0
- data/lib/log4r/rdoc/GDC +14 -0
- data/lib/log4r/rdoc/MDC +16 -0
- data/lib/log4r/rdoc/NDC +41 -0
- data/lib/log4r/rdoc/configurator +243 -0
- data/lib/log4r/rdoc/emailoutputter +103 -0
- data/lib/log4r/rdoc/formatter +39 -0
- data/lib/log4r/rdoc/log4r +89 -0
- data/lib/log4r/rdoc/logger +175 -0
- data/lib/log4r/rdoc/logserver +85 -0
- data/lib/log4r/rdoc/outputter +108 -0
- data/lib/log4r/rdoc/patternformatter +128 -0
- data/lib/log4r/rdoc/scribeoutputter +16 -0
- data/lib/log4r/rdoc/syslogoutputter +29 -0
- data/lib/log4r/rdoc/win32eventoutputter +7 -0
- data/lib/log4r/rdoc/yamlconfigurator +20 -0
- data/lib/log4r/repository.rb +88 -0
- data/lib/log4r/staticlogger.rb +49 -0
- data/lib/log4r/yamlconfigurator.rb +196 -0
- data/tests/README +10 -0
- data/tests/testGDC.rb +26 -0
- data/tests/testMDC.rb +42 -0
- data/tests/testNDC.rb +27 -0
- data/tests/testall.rb +6 -0
- data/tests/testbase.rb +49 -0
- data/tests/testchainsaw.rb +48 -0
- data/tests/testcoloroutput.rb +14 -0
- data/tests/testconf.xml +37 -0
- data/tests/testcustom.rb +27 -0
- data/tests/testformatter.rb +27 -0
- data/tests/testlogger.rb +196 -0
- data/tests/testoutputter.rb +132 -0
- data/tests/testpatternformatter.rb +78 -0
- data/tests/testthreads.rb +35 -0
- data/tests/testxmlconf.rb +45 -0
- metadata +195 -0
data/tests/testcustom.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
# tests the customization of Log4r levels
|
3
|
+
class TestCustom < TestCase
|
4
|
+
def test_validation
|
5
|
+
assert_exception(TypeError) { Configurator.custom_levels "lowercase" }
|
6
|
+
assert_exception(TypeError) { Configurator.custom_levels "With space" }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_create
|
10
|
+
assert_no_exception { Configurator.custom_levels "Foo", "Bar", "Baz" }
|
11
|
+
assert_no_exception { Configurator.custom_levels }
|
12
|
+
assert_no_exception { Configurator.custom_levels "Bogus", "Levels" }
|
13
|
+
end
|
14
|
+
def test_methods
|
15
|
+
l = Logger.new 'custom1'
|
16
|
+
assert_respond_to(:foo, l)
|
17
|
+
assert_respond_to(:foo?, l)
|
18
|
+
assert_respond_to(:bar, l)
|
19
|
+
assert_respond_to(:bar?, l)
|
20
|
+
assert_respond_to(:baz, l)
|
21
|
+
assert_respond_to(:baz?, l)
|
22
|
+
assert_no_exception(NameError) { Bar }
|
23
|
+
assert_no_exception(NameError) { Baz }
|
24
|
+
assert_no_exception(NameError) { Foo }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class TestFormatter < TestCase
|
2
|
+
def test_creation
|
3
|
+
assert_no_exception { Formatter.new.format(3) }
|
4
|
+
assert_no_exception { DefaultFormatter.new }
|
5
|
+
assert_kind_of(Formatter, DefaultFormatter.new)
|
6
|
+
end
|
7
|
+
def test_simple_formatter
|
8
|
+
sf = SimpleFormatter.new
|
9
|
+
f = Logger.new('simple formatter')
|
10
|
+
event = LogEvent.new(0, f, nil, "some data")
|
11
|
+
assert_match(sf.format(event), /simple formatter/)
|
12
|
+
end
|
13
|
+
def test_basic_formatter
|
14
|
+
b = BasicFormatter.new
|
15
|
+
f = Logger.new('fake formatter')
|
16
|
+
event = LogEvent.new(0, f, caller, "fake formatter")
|
17
|
+
event2 = LogEvent.new(0, f, nil, "fake formatter")
|
18
|
+
# this checks for tracing
|
19
|
+
assert_match(b.format(event), /in/)
|
20
|
+
assert_not_match(b.format(event2), /in/)
|
21
|
+
e = ArgumentError.new("argerror")
|
22
|
+
e.set_backtrace ['backtrace']
|
23
|
+
event3 = LogEvent.new(0, f, nil, e)
|
24
|
+
assert_match(b.format(event3), /ArgumentError/)
|
25
|
+
assert_match(b.format(LogEvent.new(0,f,nil,[1,2,3])), /Array/)
|
26
|
+
end
|
27
|
+
end
|
data/tests/testlogger.rb
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
class MyFormatter1 < Formatter
|
2
|
+
def format(event)
|
3
|
+
return "MyFormatter1\n"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class MyFormatter2 < Formatter
|
8
|
+
def format(event)
|
9
|
+
return "MyFormatter2\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestLogger < TestCase
|
14
|
+
def test_root
|
15
|
+
l1 = Logger.root
|
16
|
+
l2 = Logger['root']
|
17
|
+
l3 = Logger.global
|
18
|
+
assert(l1 == l2, "RootLogger wasn't singleton!")
|
19
|
+
assert(l1 == l3)
|
20
|
+
assert(l1.is_root? == true, "is_root? not working")
|
21
|
+
assert(l1.parent == nil, "Root's parent wasn't nil!")
|
22
|
+
end
|
23
|
+
def test_validation
|
24
|
+
assert_exception(ArgumentError) { Logger.new }
|
25
|
+
assert_no_exception { Logger.new('validate', nil) }
|
26
|
+
end
|
27
|
+
def test_all_off
|
28
|
+
l = Logger.new("create_method")
|
29
|
+
l.level = WARN
|
30
|
+
assert(l.debug? == false)
|
31
|
+
assert(l.info? == false)
|
32
|
+
assert(l.warn? == true)
|
33
|
+
assert(l.error? == true)
|
34
|
+
assert(l.fatal? == true)
|
35
|
+
assert(l.off? == false)
|
36
|
+
assert(l.all? == false)
|
37
|
+
l.level = OFF
|
38
|
+
assert(l.off? == true)
|
39
|
+
assert(l.all? == false)
|
40
|
+
l.level = ALL
|
41
|
+
assert(l.off? == false)
|
42
|
+
assert(l.all? == true)
|
43
|
+
end
|
44
|
+
def test_add_outputters
|
45
|
+
StdoutOutputter.new('fake1')
|
46
|
+
StdoutOutputter.new('fake2')
|
47
|
+
a = Logger.new("add")
|
48
|
+
assert_exception(TypeError) { a.add 'bogus' }
|
49
|
+
assert_exception(TypeError) { a.add Class }
|
50
|
+
assert_exception(TypeError) { a.add 'fake1', Class }
|
51
|
+
assert_no_exception { a.add 'fake1', 'fake2' }
|
52
|
+
end
|
53
|
+
def test_repository
|
54
|
+
assert_exception(NameError) { Logger.get('bogusbogus') }
|
55
|
+
assert_no_exception { Logger['bogusbogus'] }
|
56
|
+
end
|
57
|
+
def test_heiarchy
|
58
|
+
a = Logger.new("a")
|
59
|
+
a.additive = true
|
60
|
+
assert(a.name == "a", "name wasn't set properly")
|
61
|
+
assert(a.path == "", "path wasn't set properly")
|
62
|
+
assert(a.level == Logger.root.level, "didn't inherit root's level")
|
63
|
+
assert(a.parent == Logger.root)
|
64
|
+
a.level = WARN
|
65
|
+
b = Logger.new("a::b")
|
66
|
+
assert(b.name == "b", "name wasn't set properly")
|
67
|
+
assert(b.path == "a", "path wasn't set properly")
|
68
|
+
assert(b.level == a.level, "didn't inherit parent's level")
|
69
|
+
assert(b.parent == a, "parent wasn't what is expected")
|
70
|
+
c = Logger.new("a::b::c")
|
71
|
+
assert(Logger["a::b::c"] == c)
|
72
|
+
assert(c.name == "c", "name wasn't set properly")
|
73
|
+
assert(c.path == "a::b", "path wasn't set properly")
|
74
|
+
assert(c.level == b.level, "didn't inherit parent's level")
|
75
|
+
assert(c.parent == b, "parent wasn't what is expected")
|
76
|
+
d = Logger.new("a::d")
|
77
|
+
assert(Logger["a::d"] == d)
|
78
|
+
assert(d.name == "d", "name wasn't set properly")
|
79
|
+
assert(d.path == "a", "path wasn't set properly")
|
80
|
+
assert(d.level == a.level, "didn't inherit parent's level")
|
81
|
+
assert(d.parent == a, "parent wasn't what is expected")
|
82
|
+
assert_exception(ArgumentError) { Logger.new("::a") }
|
83
|
+
end
|
84
|
+
def test_undefined_parents
|
85
|
+
a = Logger.new 'has::no::real::parents::me'
|
86
|
+
assert(a.parent == Logger.root)
|
87
|
+
b = Logger.new 'has::no::real::parents::me::child'
|
88
|
+
assert(b.parent == a)
|
89
|
+
c = Logger.new 'has::no::real::parents::metoo'
|
90
|
+
assert(c.parent == Logger.root)
|
91
|
+
p = Logger.new 'has::no::real::parents'
|
92
|
+
assert(p.parent == Logger.root)
|
93
|
+
assert(a.parent == p)
|
94
|
+
assert(b.parent == a)
|
95
|
+
assert(c.parent == p)
|
96
|
+
Logger.each{|fullname, logger|
|
97
|
+
if logger != a and logger != c
|
98
|
+
assert(logger.parent != p)
|
99
|
+
end
|
100
|
+
}
|
101
|
+
end
|
102
|
+
def test_levels
|
103
|
+
l = Logger.new("levels", WARN)
|
104
|
+
assert(l.level == WARN, "level wasn't changed")
|
105
|
+
assert(l.fatal? == true)
|
106
|
+
assert(l.error? == true)
|
107
|
+
assert(l.warn? == true)
|
108
|
+
assert(l.info? == false)
|
109
|
+
assert(l.debug? == false)
|
110
|
+
l.debug "debug message should NOT show up"
|
111
|
+
l.info "info message should NOT show up"
|
112
|
+
l.warn "warn messge should show up. 3 total"
|
113
|
+
l.error "error messge should show up. 3 total"
|
114
|
+
l.fatal "fatal messge should show up. 3 total"
|
115
|
+
l.level = ERROR
|
116
|
+
assert(l.level == ERROR, "level wasn't changed")
|
117
|
+
assert(l.fatal? == true)
|
118
|
+
assert(l.error? == true)
|
119
|
+
assert(l.warn? == false)
|
120
|
+
assert(l.info? == false)
|
121
|
+
assert(l.debug? == false)
|
122
|
+
l.debug "debug message should NOT show up"
|
123
|
+
l.info "info message should NOT show up"
|
124
|
+
l.warn "warn messge should NOT show up."
|
125
|
+
l.error "error messge should show up. 2 total"
|
126
|
+
l.fatal "fatal messge should show up. 2 total"
|
127
|
+
l.level = WARN
|
128
|
+
end
|
129
|
+
def test_log_blocks
|
130
|
+
l = Logger.new 'logblocks'
|
131
|
+
l.level = WARN
|
132
|
+
l.add(Outputter.stdout)
|
133
|
+
assert_no_exception {
|
134
|
+
l.debug { puts "should not show up"; "LOGBLOCKS" }
|
135
|
+
l.fatal { puts "should show up"; "LOGBLOCKS" }
|
136
|
+
l.fatal { nil }
|
137
|
+
l.fatal {}
|
138
|
+
}
|
139
|
+
end
|
140
|
+
def test_heiarchial_logging
|
141
|
+
a = Logger.new("one")
|
142
|
+
a.add(StdoutOutputter.new 'so1')
|
143
|
+
b = Logger.new("one::two")
|
144
|
+
b.add(StdoutOutputter.new 'so2')
|
145
|
+
c = Logger.new("one::two::three")
|
146
|
+
c.add(StdoutOutputter.new 'so3')
|
147
|
+
d = Logger.new("one::two::three::four")
|
148
|
+
d.add(StdoutOutputter.new 'so4')
|
149
|
+
d.additive = false
|
150
|
+
e = Logger.new("one::two::three::four::five")
|
151
|
+
e.add(StdoutOutputter.new 'so5')
|
152
|
+
|
153
|
+
a.fatal "statement from a should show up once"
|
154
|
+
b.fatal "statement from b should show up twice"
|
155
|
+
c.fatal "statement from c should show up thrice"
|
156
|
+
d.fatal "statement from d should show up once"
|
157
|
+
e.fatal "statement from e should show up twice"
|
158
|
+
end
|
159
|
+
def test_multi_outs
|
160
|
+
f1 = FileOutputter.new('f1', :filename => "./junk/tmp1.log", :level=>ALL)
|
161
|
+
f2 = FileOutputter.new('f2', :filename => "./junk/tmp2.log", :level=>DEBUG)
|
162
|
+
f3 = FileOutputter.new('f3', :filename => "./junk/tmp3.log", :level=>ERROR)
|
163
|
+
f4 = FileOutputter.new('f4', :filename => "./junk/tmp4.log", :level=>FATAL)
|
164
|
+
|
165
|
+
l = Logger.new("multi")
|
166
|
+
l.add(f1, f3, f4)
|
167
|
+
|
168
|
+
a = Logger.new("multi::multi2")
|
169
|
+
a.level = ERROR
|
170
|
+
a.add(f2, f4)
|
171
|
+
|
172
|
+
l.debug "debug test_multi_outputters"
|
173
|
+
l.info "info test_multi_outputters"
|
174
|
+
l.warn "warn test_multi_outputters"
|
175
|
+
l.error "error test_multi_outputters"
|
176
|
+
l.fatal "fatal test_multi_outputters"
|
177
|
+
|
178
|
+
a.debug "debug test_multi_outputters"
|
179
|
+
a.info "info test_multi_outputters"
|
180
|
+
a.warn "warn test_multi_outputters"
|
181
|
+
a.error "error test_multi_outputters"
|
182
|
+
a.fatal "fatal test_multi_outputters"
|
183
|
+
|
184
|
+
f1.close; f2.close; f3.close; f4.close
|
185
|
+
end
|
186
|
+
def test_custom_formatter
|
187
|
+
l = Logger.new('custom_formatter')
|
188
|
+
o = StdoutOutputter.new('formatter'=>MyFormatter1.new)
|
189
|
+
l.add o
|
190
|
+
l.error "try myformatter1"
|
191
|
+
l.fatal "try myformatter1"
|
192
|
+
o.formatter = MyFormatter2.new
|
193
|
+
l.error "try formatter2"
|
194
|
+
l.fatal "try formatter2"
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
$: << File.join("..","lib")
|
2
|
+
require "test/unit"
|
3
|
+
require "log4r"
|
4
|
+
include Log4r
|
5
|
+
|
6
|
+
|
7
|
+
class TestOutputter < Test::Unit::TestCase
|
8
|
+
def test_validation
|
9
|
+
assert_raise(ArgumentError) { Outputter.new }
|
10
|
+
assert_raise(ArgumentError) { Outputter.new 'fonda', :level=>-10}
|
11
|
+
assert_raise(TypeError) { Outputter.new 'fonda', :formatter=>-10}
|
12
|
+
end
|
13
|
+
def test_io
|
14
|
+
assert_nothing_raised {
|
15
|
+
IOOutputter.new('foo3', $stdout)
|
16
|
+
IOOutputter.new('foo4', $stderr)
|
17
|
+
}
|
18
|
+
f = File.new("junk/tmpx.log", "w")
|
19
|
+
o = IOOutputter.new('asdf', f)
|
20
|
+
o.close
|
21
|
+
assert(f.closed? == true)
|
22
|
+
assert(o.level == OFF)
|
23
|
+
end
|
24
|
+
def test_repository
|
25
|
+
assert( Outputter['foo3'].class == IOOutputter )
|
26
|
+
assert( Outputter['foo4'].class == IOOutputter )
|
27
|
+
assert( Outputter['asdf'].class == IOOutputter )
|
28
|
+
end
|
29
|
+
def test_validation_and_creation
|
30
|
+
assert_nothing_raised {
|
31
|
+
StdoutOutputter.new('out', 'level'=>DEBUG)
|
32
|
+
FileOutputter.new('file', 'filename'=>'junk/test', :trunc=>true)
|
33
|
+
}
|
34
|
+
a = StdoutOutputter.new 'out2'
|
35
|
+
assert(a.level == Logger.root.level)
|
36
|
+
assert(a.formatter.class == DefaultFormatter)
|
37
|
+
b = StdoutOutputter.new('ook', :level => DEBUG, :formatter => Formatter)
|
38
|
+
assert(b.level == DEBUG)
|
39
|
+
assert(b.formatter.class == Formatter)
|
40
|
+
c = StdoutOutputter.new('akk', :formatter => Formatter)
|
41
|
+
assert(c.level == Logger.root.level)
|
42
|
+
assert(c.formatter.class == Formatter)
|
43
|
+
c = StderrOutputter.new('iikk', :level => OFF)
|
44
|
+
assert(c.level == OFF)
|
45
|
+
assert(c.formatter.class == DefaultFormatter)
|
46
|
+
o = StderrOutputter.new 'ik'
|
47
|
+
assert_nothing_raised(TypeError) { o.formatter = DefaultFormatter }
|
48
|
+
assert(o.formatter.class == DefaultFormatter)
|
49
|
+
end
|
50
|
+
# test the resource= bounds
|
51
|
+
def test_boundaries
|
52
|
+
o = StderrOutputter.new('ak', :formatter => Formatter)
|
53
|
+
assert_raise(TypeError) { o.formatter = nil }
|
54
|
+
assert_raise(TypeError) { o.formatter = String }
|
55
|
+
assert_raise(TypeError) { o.formatter = "bogus" }
|
56
|
+
assert_raise(TypeError) { o.formatter = -3 }
|
57
|
+
# the formatter should be preserved
|
58
|
+
assert(o.formatter.class == Formatter)
|
59
|
+
end
|
60
|
+
def test_file
|
61
|
+
assert_raise(TypeError) { FileOutputter.new 'f' }
|
62
|
+
assert_raise(TypeError) { FileOutputter.new('fa', :filename => DEBUG) }
|
63
|
+
assert_raise(TypeError) { FileOutputter.new('fo', :filename => nil) }
|
64
|
+
assert_nothing_raised {
|
65
|
+
FileOutputter.new('fi', :filename => './junk/tmp')
|
66
|
+
FileOutputter.new('fum', :filename=>'./junk/tmp', :trunc => "true")
|
67
|
+
}
|
68
|
+
fo = FileOutputter.new('food', :filename => './junk/tmp', :trunc => false)
|
69
|
+
assert(fo.trunc == false)
|
70
|
+
assert(fo.filename == './junk/tmp')
|
71
|
+
assert(fo.closed? == false)
|
72
|
+
fo.close
|
73
|
+
assert(fo.closed? == true)
|
74
|
+
assert(fo.level == OFF)
|
75
|
+
end
|
76
|
+
# test the dynamic definition of outputter log messages
|
77
|
+
def test_log_methods
|
78
|
+
o = StderrOutputter.new('so1', :level => WARN )
|
79
|
+
# test to see if all of the methods are defined
|
80
|
+
for mname in LNAMES
|
81
|
+
next if mname == 'OFF' || mname == 'ALL'
|
82
|
+
assert_respond_to(o, mname.downcase.to_sym, "Test respond to #{mname.to_s}")
|
83
|
+
end
|
84
|
+
return # cuz the rest is borked
|
85
|
+
# we rely on BasicFormatter's inability to reference a nil Logger to test
|
86
|
+
# the log methods. Everything from WARN to FATAL should choke.
|
87
|
+
event = LogEvent.new(nil, nil, nil, nil)
|
88
|
+
assert_nothing_raised { o.debug event }
|
89
|
+
assert_nothing_raised { o.info event }
|
90
|
+
assert_raise(NameError) { o.warn event }
|
91
|
+
assert_raise(NameError) { o.error event }
|
92
|
+
assert_raise(NameError) { o.fatal event }
|
93
|
+
# now let's dynamically change the level and repeat
|
94
|
+
o.level = ERROR
|
95
|
+
assert_nothing_raised { o.debug event}
|
96
|
+
assert_nothing_raised { o.info event}
|
97
|
+
assert_nothing_raised { o.warn event}
|
98
|
+
assert_raise(NameError) { o.error event}
|
99
|
+
assert_raise(NameError) { o.fatal event}
|
100
|
+
end
|
101
|
+
def test_only_at_validation
|
102
|
+
o = StdoutOutputter.new 'so2'
|
103
|
+
assert_raise(ArgumentError) { o.only_at }
|
104
|
+
assert_raise(ArgumentError) { o.only_at ALL }
|
105
|
+
assert_raise(TypeError) { o.only_at OFF }
|
106
|
+
assert_nothing_raised { o.only_at DEBUG, ERROR }
|
107
|
+
return # cuz the rest is borked
|
108
|
+
# test the methods as before
|
109
|
+
event = LogEvent.new(nil,nil,nil,nil)
|
110
|
+
assert_raise(NameError) { o.debug event}
|
111
|
+
assert_raise(NameError) { o.error event}
|
112
|
+
assert_nothing_raised { o.warn event}
|
113
|
+
assert_nothing_raised { o.info event}
|
114
|
+
assert_nothing_raised { o.fatal event}
|
115
|
+
end
|
116
|
+
def broken_test_threading
|
117
|
+
class << self
|
118
|
+
def log_work
|
119
|
+
o = StdoutOutputter.new 'so2'
|
120
|
+
assert_nothing_raised { o.only_at DEBUG, ERROR }
|
121
|
+
Thread.current().exit()
|
122
|
+
end
|
123
|
+
def log_thread_start
|
124
|
+
t = Thread.new(log_work)
|
125
|
+
t.join
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
ts = Thread.new(log_thread_start)
|
130
|
+
ts.join
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
$: << File.join("..","lib")
|
2
|
+
require "test/unit"
|
3
|
+
require "log4r"
|
4
|
+
include Log4r
|
5
|
+
|
6
|
+
|
7
|
+
class TestPatternFormatter < Test::Unit::TestCase
|
8
|
+
def test_pattern
|
9
|
+
l = Logger.new 'test::this::that'
|
10
|
+
l.trace = true
|
11
|
+
o = StdoutOutputter.new 'test'
|
12
|
+
l.add o
|
13
|
+
assert_nothing_raised {
|
14
|
+
f = PatternFormatter.new :pattern=> "'%t' T-'%T' %d %6l [%C]%c %% %-40.30M"
|
15
|
+
#:date_pattern=> "%Y"
|
16
|
+
#:date_method => :usec
|
17
|
+
Outputter['test'].formatter = f
|
18
|
+
l.debug "And this?"
|
19
|
+
l.info "How's this?"
|
20
|
+
l.error "and a really freaking huge line which we hope will be trimmed?"
|
21
|
+
e = ArgumentError.new("something barfed")
|
22
|
+
e.set_backtrace Array.new(5, "trace junk at thisfile.rb 154")
|
23
|
+
l.fatal e
|
24
|
+
l.info [1, 3, 5]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_ndc
|
29
|
+
l = Logger.new 'test::this::that::other'
|
30
|
+
l.trace = true
|
31
|
+
o = StdoutOutputter.new 'testy'
|
32
|
+
l.add o
|
33
|
+
f = PatternFormatter.new :pattern=> "%d %6l [%C]%c {%x} %% %-40.30M"
|
34
|
+
#:date_pattern=> "%Y"
|
35
|
+
#:date_method => :usec
|
36
|
+
Outputter['testy'].formatter = f
|
37
|
+
|
38
|
+
l.info "no NDC"
|
39
|
+
NDC.push("start")
|
40
|
+
l.info "start NDC"
|
41
|
+
NDC.push("finish")
|
42
|
+
l.info "start finish NDC"
|
43
|
+
NDC.pop()
|
44
|
+
l.info "start NDC"
|
45
|
+
NDC.remove()
|
46
|
+
l.info "no NDC"
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_gdc
|
50
|
+
l = Logger.new 'test::this::that::other'
|
51
|
+
l.trace = true
|
52
|
+
o = StdoutOutputter.new 'testy'
|
53
|
+
l.add o
|
54
|
+
f = PatternFormatter.new :pattern=> "%d %6l [%C]%c {%g} %% %-40.30M"
|
55
|
+
#:date_pattern=> "%Y"
|
56
|
+
#:date_method => :usec
|
57
|
+
Outputter['testy'].formatter = f
|
58
|
+
|
59
|
+
l.info "GDC default"
|
60
|
+
GDC.set("non-default")
|
61
|
+
l.info "GDC non-default"
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_mdc
|
65
|
+
l = Logger.new 'test::this::that::other'
|
66
|
+
l.trace = true
|
67
|
+
o = StdoutOutputter.new 'testy'
|
68
|
+
l.add o
|
69
|
+
f = PatternFormatter.new :pattern=> "%d %6l [%C]%c {%X{user}} %% %-40.30M"
|
70
|
+
#:date_pattern=> "%Y"
|
71
|
+
#:date_method => :usec
|
72
|
+
Outputter['testy'].formatter = f
|
73
|
+
|
74
|
+
l.info "no user"
|
75
|
+
MDC.put("user","colbygk")
|
76
|
+
l.info "user colbygk"
|
77
|
+
end
|
78
|
+
end
|