rjack-logback 0.9.18.1-java

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ === 0.9.18.1 (2010-3-6)
2
+ * Set gem platform to java
3
+ * Upgraded to tarpit ~> 1.2.0
4
+
5
+ === 0.9.18.0 (2009-12-19)
6
+ * Upgraded to Logback 0.9.18
7
+ * Match Logback's new dual licensing under the Eclipse Public License (EPL).
8
+ * Upgraded to tarpit-1.1.0 (gemcutter)
9
+
10
+ === 0.9.17.1 (2009-10-10)
11
+ * Renamed gem rjack-logback and as module RJack::Logback (with ::Logback
12
+ alias kept for backward compatibility.)
13
+ * Use rjack-tarpit for build.
14
+ * Upgraded to Logback 0.9.17
15
+ * Update/relax rjack-slf4j dependency to '~> 1.5.8' (tested with slf4j 1.5.8.1).
16
+ * Added Logback.config_console( :mdc => [ :key ] ) option
17
+
18
+ === 0.9.15.2 (2009-5-8)
19
+ * Added Logback.config_console({}) convenience config method.
20
+ * Use rdoc 2.4.3 and hoe 1.12.2 for build, and general rdoc
21
+ improvements.
22
+
23
+ === 0.9.15.1 (2009-2-15)
24
+ * Upgraded to Logback 0.9.15
25
+ * Fixed fuzzy slf4j dependency as "~> 1.5.6.1"
26
+
27
+ === 0.9.14.1 (2009-1-4)
28
+ * Upgraded to Logback 0.9.14
29
+
30
+ === 0.9.13.1 (2008-12-6)
31
+ * Upgraded to Logback 0.9.13
32
+ * Updated SLF4J dependency to ~> 1.5.6
33
+ * LogbackBase -rename-> Logback
34
+
35
+ === 0.9.11.1 (2008-11-1)
36
+ * Upgraded to Logback 0.9.11
37
+ * Updated SLF4J dependency to ~> 1.5.5
38
+
39
+ === 0.9.9.1 (2008-10-8)
40
+ * Initial release based on Logback 0.9.9
data/Manifest.static ADDED
@@ -0,0 +1,11 @@
1
+ Manifest.static
2
+ Manifest.txt
3
+ README.rdoc
4
+ History.rdoc
5
+ Rakefile
6
+ pom.xml
7
+ assembly.xml
8
+ lib/rjack-logback/base.rb
9
+ lib/rjack-logback.rb
10
+ lib/rjack-logback/access.rb
11
+ test/test_logback.rb
data/Manifest.txt ADDED
@@ -0,0 +1,14 @@
1
+ Manifest.static
2
+ Manifest.txt
3
+ README.rdoc
4
+ History.rdoc
5
+ Rakefile
6
+ pom.xml
7
+ assembly.xml
8
+ lib/rjack-logback/base.rb
9
+ lib/rjack-logback.rb
10
+ lib/rjack-logback/access.rb
11
+ test/test_logback.rb
12
+ lib/rjack-logback/logback-access-0.9.18.jar
13
+ lib/rjack-logback/logback-classic-0.9.18.jar
14
+ lib/rjack-logback/logback-core-0.9.18.jar
data/README.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ = rjack-logback
2
+
3
+ * http://rjack.rubyforge.org
4
+ * http://rubyforge.org/projects/rjack
5
+
6
+ == Description
7
+
8
+ The Logback ruby gem packages the Logback[http://logback.qos.ch/] java log
9
+ writer, and provides a JRuby facade for programmatic Logback
10
+ setup. Logback implements the SLF4J[http://www.slf4j.org/] SPI
11
+ packaged in the {slf4j gem}[http://rjack.rubyforge.org/slf4j/].
12
+
13
+ == Synopsis
14
+
15
+ require 'rjack-logback'
16
+ RJack::Logback.config_console( :level => Logback:INFO )
17
+
18
+ log = RJack::SLF4J[ "my.app.logger" ]
19
+ log.info "Hello World!"
20
+
21
+ == License
22
+
23
+ === rjack-logback gem
24
+
25
+ Copyright (c) 2008-2009 David Kellum
26
+
27
+ rjack-logback is free software: you can redistribute it and/or
28
+ modify it under the terms of either of following licenses:
29
+
30
+ * {GNU Lesser General Public License}[http://www.gnu.org/licenses/lgpl.html]
31
+ v3 or later
32
+ * {Eclipse Public License v1.0}[http://www.eclipse.org/legal/epl-v10.html]
33
+
34
+ rjack-logback is distributed in the hope that it will be useful, but
35
+ WITHOUT ANY WARRANTY; without even the implied warranty of
36
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
37
+
38
+ === Logback (java)
39
+
40
+ Copyright (c) 1999-2009, QOS.ch
41
+
42
+ This program and the accompanying materials are dual-licensed under
43
+ either the terms of the Eclipse Public License v1.0 as published by
44
+ the Eclipse Foundation or (per the licensee's choosing) under the
45
+ terms of the GNU Lesser General Public License version 2.1 as
46
+ published by the Free Software Foundation.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ # -*- ruby -*-
2
+ #--
3
+ # Copyright (C) 2008-2009 David Kellum
4
+ #
5
+ # rjack-logback is free software: you can redistribute it and/or
6
+ # modify it under the terms of either of following licenses:
7
+ #
8
+ # GNU Lesser General Public License v3 or later
9
+ # Eclipse Public License v1.0
10
+ #
11
+ # rjack-logback is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+ #++
15
+
16
+ $LOAD_PATH << './lib'
17
+ require 'rjack-logback/base'
18
+
19
+ require 'rubygems'
20
+ gem 'rjack-tarpit', '~> 1.2.0'
21
+ require 'rjack-tarpit'
22
+
23
+ include RJack
24
+
25
+ t = TarPit.new( 'rjack-logback', Logback::VERSION, :java_platform )
26
+
27
+ t.specify do |h|
28
+ h.developer( "David Kellum", "dek-oss@gravitext.com" )
29
+ h.extra_deps << [ 'rjack-slf4j', '~> 1.5.8' ]
30
+ h.rubyforge_name = "rjack"
31
+ h.remote_rdoc_dir = "logback"
32
+ end
33
+
34
+ t.jars = %w{ core classic access }.map do |n|
35
+ "logback-#{n}-#{ Logback::LOGBACK_VERSION }.jar"
36
+ end
37
+
38
+ file 'Manifest.txt' => [ "lib/#{t.name}/base.rb" ]
39
+
40
+ t.assembly_version = 1.0
41
+
42
+ task :check_pom_deps do
43
+ t.test_line_match( 'pom.xml',
44
+ %r[<version>#{ Logback::LOGBACK_VERSION }</version>] )
45
+ end
46
+ task :check_history_version do
47
+ t.test_line_match( 'History.rdoc', /^==/, / #{t.version} / )
48
+ end
49
+ task :check_history_date do
50
+ t.test_line_match( 'History.rdoc', /^==/, /\([0-9\-]+\)$/ )
51
+ end
52
+
53
+ task :gem => [ :check_pom_deps, :check_history_version ]
54
+ task :tag => [ :check_pom_deps, :check_history_version, :check_history_date ]
55
+ task :push => [ :check_history_date ]
56
+
57
+ t.define_tasks
data/assembly.xml ADDED
@@ -0,0 +1,17 @@
1
+ <assembly>
2
+ <id>bin</id>
3
+ <formats>
4
+ <format>dir</format>
5
+ </formats>
6
+ <includeBaseDirectory>false</includeBaseDirectory>
7
+ <dependencySets>
8
+ <dependencySet>
9
+ <includes>
10
+ <include>ch.qos.logback:logback-classic</include>
11
+ <include>ch.qos.logback:logback-core</include>
12
+ <include>ch.qos.logback:logback-access</include>
13
+ </includes>
14
+ </dependencySet>
15
+ </dependencySets>
16
+
17
+ </assembly>
@@ -0,0 +1,320 @@
1
+ #--
2
+ # Copyright (C) 2008-2009 David Kellum
3
+ #
4
+ # rjack-logback is free software: you can redistribute it and/or
5
+ # modify it under the terms of either of following licenses:
6
+ #
7
+ # GNU Lesser General Public License v3 or later
8
+ # Eclipse Public License v1.0
9
+ #
10
+ # rjack-logback is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ #++
14
+
15
+ require 'rubygems'
16
+ require 'java'
17
+
18
+ require 'rjack-slf4j'
19
+ require 'rjack-logback/base'
20
+
21
+ # Backward compatibility for top level ::Logback module
22
+ Logback = RJack::Logback
23
+
24
+ module RJack
25
+
26
+ # Jruby wrapper module for the Logback[http://logback.qos.ch/] log writer.
27
+ # Programmatic configuration and setting of logger output levels is supported.
28
+ #
29
+ # == Examples
30
+ #
31
+ # === High level configuration
32
+ #
33
+ # require 'rjack-logback'
34
+ #
35
+ # RJack::Logback.config_console( :thread => true, :level => Logback:INFO )
36
+ #
37
+ # === Low level configuration
38
+ #
39
+ # require 'rjack-logback'
40
+ #
41
+ # log = RJack::SLF4J[ 'example' ]
42
+ # log.info "About to reconfigure..."
43
+ #
44
+ # RJack::Logback.configure do
45
+ # console = RJack::Logback::ConsoleAppender.new do |a|
46
+ # a.target = "System.err"
47
+ # a.layout = RJack::Logback::PatternLayout.new do |p|
48
+ # p.pattern = "%r %-5level %logger{35} - %msg %ex%n"
49
+ # end
50
+ # end
51
+ # RJack::Logback.root.add_appender( console )
52
+ # RJack::Logback.root.level = Logback::INFO
53
+ # end
54
+ #
55
+ # # Adjust output levels (also works outside of configure )
56
+ # RJack::Logback[ 'example' ].level = Logback::DEBUG
57
+ #
58
+ # log.debug "...after reconfigure."
59
+ #
60
+ # Configure with Logback XML configuration:
61
+ #
62
+ # RJack::Logback.configure do
63
+ # RJack::Logback.load_xml_config( 'sample-logback.xml' )
64
+ # end
65
+ #
66
+ # == Programmatic Configuration Support
67
+ #
68
+ # Logback java classes implement interfaces +LifeCycle+ and
69
+ # +ContextAware+ for configurability with Joran (XML). To simplify
70
+ # configuration in ruby, the following classes have been extended:
71
+ #
72
+ # * ConsoleAppender
73
+ # * FileAppender
74
+ # * PatternLayout
75
+ #
76
+ # The extensions provide a block initializer which sets sensible
77
+ # defaults, yields to a block for customization, and then calls
78
+ # +start+. Logback provides many other components not yet extended in
79
+ # this way. These can be created directly and or extended in a
80
+ # similar fashion externally. Consider providing a patch to the
81
+ # rjack[http://rubyforge.org/projects/rjack] project with desired
82
+ # extensions.
83
+ #
84
+ module Logback
85
+
86
+ # Load logback jar.
87
+ def self.require_jar( name )
88
+ require File.join( LOGBACK_DIR, "#{name}-#{ LOGBACK_VERSION }.jar" )
89
+ end
90
+
91
+ require_jar 'logback-core'
92
+ require_jar 'logback-classic'
93
+
94
+ # ch.qos.logback.classic.Level
95
+ Level = Java::ch.qos.logback.classic.Level
96
+
97
+ # Level::TRACE
98
+ TRACE = Level::TRACE
99
+
100
+ # Level::DEBUG
101
+ DEBUG = Level::DEBUG
102
+
103
+ # Level::INFO
104
+ INFO = Level::INFO
105
+
106
+ # Level::WARN
107
+ WARN = Level::WARN
108
+
109
+ # Level::ERROR
110
+ ERROR = Level::ERROR
111
+
112
+ DEFAULT_PATTERN = "%date [%thread] %-5level %logger{35} - %msg %ex%n" #:nodoc:
113
+
114
+ @@context = SLF4J.linked_factory
115
+
116
+ # Returns the LoggerContext
117
+ def self.context
118
+ @@context
119
+ end
120
+
121
+ # Utility mixin of Logback ch.qos.logback.core.spi.LifeCycle instances
122
+ module Util
123
+ # Start, raise if not started
124
+ def self.start( lifecycle_obj )
125
+ lifecycle_obj.start
126
+ raise "#{lifecycle_obj.class.name} did not start" if ! lifecycle_obj.started?
127
+ end
128
+ end
129
+
130
+ # Wrapper for
131
+ # ch.qos.logback.classic.Logger[http://logback.qos.ch/apidocs/ch/qos/logback/classic/Logger.html]
132
+ class Logger
133
+
134
+ # Initialize given ch.qos.logback.classic.Logger
135
+ def initialize( jlogger )
136
+ @jlogger = jlogger
137
+ end
138
+
139
+ # Set output level
140
+ # ==== Parameters
141
+ # :level<Level>:: New output Level.
142
+ def level=( level )
143
+ @jlogger.level = level
144
+ end
145
+
146
+ # Add appender to this logger
147
+ # ==== Parameters
148
+ # :appender<ch.qos.logback.core.Appender>:: Appender
149
+ def add_appender( appender )
150
+ @jlogger.add_appender( appender )
151
+ end
152
+
153
+ # Set additive flag ( false means events stop at attached appender )
154
+ def additive=( is_additive )
155
+ @jlogger.additive = is_additive
156
+ end
157
+ end
158
+
159
+ # ch.qos.logback.classic.joran.JoranConfigurator
160
+ JoranConfigurator = Java::ch.qos.logback.classic.joran.JoranConfigurator
161
+
162
+ # Load the specified Logback (Joran) XML configuration file. Should be
163
+ # called within a configure {...} block.
164
+ def self.load_xml_config( file )
165
+ cfger = JoranConfigurator.new
166
+ cfger.context = @@context
167
+ cfger.doConfigure( file )
168
+ end
169
+
170
+ # ch.qos.logback.classic.PatternLayout
171
+ JPatternLayout = Java::ch.qos.logback.classic.PatternLayout
172
+
173
+ # Extends
174
+ # ch.qos.logback.classic.PatternLayout[http://logback.qos.ch/apidocs/ch/qos/logback/classic/PatternLayout.html]
175
+ # with a block initializer.
176
+ class PatternLayout < JPatternLayout
177
+
178
+ # Sets context and pattern, yields self to block, and calls self.start
179
+ def initialize( pattern=DEFAULT_PATTERN )
180
+ super()
181
+ self.context = Logback.context
182
+ self.pattern = pattern
183
+ yield( self ) if block_given?
184
+ Util.start( self )
185
+ end
186
+ end
187
+
188
+ # Utility implementation mixin for Appenders.
189
+ module AppenderUtil
190
+ @@default_layout = Logback::PatternLayout.new
191
+
192
+ # Set appender defaults.
193
+ def set_defaults
194
+ self.context = Logback.context
195
+ self.name = self.class.name
196
+ self.layout = @@default_layout
197
+ end
198
+
199
+ # Yield to block, then start.
200
+ def finish( &block )
201
+ block.call( self ) unless block.nil?
202
+ Util.start( self )
203
+ end
204
+ end
205
+
206
+ # ch.qos.logback.core.ConsoleAppender
207
+ JConsoleAppender = Java::ch.qos.logback.core.ConsoleAppender
208
+
209
+ # Extends
210
+ # ch.qos.logback.core.ConsoleAppender[http://logback.qos.ch/apidocs/ch/qos/logback/core/ConsoleAppender.html]
211
+ # with a block initializer.
212
+ class ConsoleAppender < JConsoleAppender
213
+ include AppenderUtil
214
+
215
+ # Sets context, default name and layout, yields self to block, and
216
+ # calls self.start
217
+ def initialize( &block )
218
+ super()
219
+ set_defaults
220
+ finish( &block )
221
+ end
222
+ end
223
+
224
+ # ch.qos.logback.core.FileAppender
225
+ JFileAppender = Java::ch.qos.logback.core.FileAppender
226
+
227
+ # Extends
228
+ # ch.qos.logback.core.FileAppender[http://logback.qos.ch/apidocs/ch/qos/logback/core/FileAppender.html]
229
+ # with a block initializer.
230
+ #
231
+ # Note that if buffered (immediate_flush = false, buffer_size > 0),
232
+ # you will need to +stop+ the appender before exiting in order to
233
+ # flush/close the log. Calling:
234
+ #
235
+ # Logback.configure {}
236
+ #
237
+ # Will also result in the log being flushed and closed.
238
+ #
239
+ class FileAppender < JFileAppender
240
+ include AppenderUtil
241
+
242
+ # Sets defaults, yields self to block, and calls self.start
243
+ def initialize( file_name, append = true, &block )
244
+ super()
245
+ set_defaults
246
+ self.file = file_name
247
+ self.append = append
248
+ self.immediate_flush = true #default
249
+ self.encoding = "UTF-8"
250
+ finish( &block )
251
+ end
252
+ end
253
+
254
+ # Configure Logback with the specified block. The Logback context is
255
+ # +reset+, yielded to block, and then started after return
256
+ # from the block.
257
+ def self.configure
258
+ @@context.reset
259
+
260
+ yield context
261
+
262
+ Util.start( context )
263
+ nil
264
+ end
265
+
266
+ # Configure a single ConsoleAppender using options hash.
267
+ # ==== Options
268
+ # :stderr:: Output to standard error? (default: false)
269
+ # :full:: Output full date? (default: false, milliseconds)
270
+ # :thread:: Output thread name? (default: false)
271
+ # :level<Level>:: Set root level (default: INFO)
272
+ # :lwidth<~to_s>:: Logger width (default: :full ? 35 : 30)
273
+ # :mdc<String|Array[String]>:: One or more Mapped Diagnostic Context keys
274
+ # :mdc_width<~to_s}:: MDC width (default: unspecified)
275
+ def self.config_console( options = {} )
276
+ configure do
277
+ console = Logback::ConsoleAppender.new do |a|
278
+ a.target = "System.err" if options[ :stderr ]
279
+ a.layout = Logback::PatternLayout.new do |layout|
280
+ pat = [ options[ :full ] ? '%date' : '%-4r' ]
281
+ pat << '[%thread]' if options[ :thread ]
282
+ pat << '%-5level'
283
+
284
+ w = ( options[ :lwidth ] || ( options[ :full ] ? 35 : 30 ) )
285
+ pat << "%logger{#{w}}"
286
+
287
+ mdcs = options[ :mdc ].to_a.map { |k| "%X{#{k}}" }
288
+ unless mdcs.empty?
289
+ mp = ( '\(' + mdcs.join(',') + '\)' )
290
+ mw = options[ :mdc_width ]
291
+ mp = "%-#{mw}(#{mp})" if mw
292
+ pat << mp
293
+ end
294
+
295
+ pat += [ '-', '%msg' '%ex%n' ]
296
+ layout.pattern = pat.join( ' ' )
297
+ end
298
+ end
299
+ Logback.root.add_appender( console )
300
+ Logback.root.level = options[ :level ] || INFO
301
+ end
302
+ end
303
+
304
+ # Returns the named Logger
305
+ def self.logger( name )
306
+ Logger.new( @@context.getLogger( name ) )
307
+ end
308
+
309
+ # Synonym for logger(name)
310
+ def self.[](name)
311
+ logger( name )
312
+ end
313
+
314
+ # Returns the special "root" Logger
315
+ def self.root
316
+ logger( "root" )
317
+ end
318
+
319
+ end
320
+ end
@@ -0,0 +1 @@
1
+ RJack::Logback.require_jar 'logback-access'
@@ -0,0 +1,25 @@
1
+ #--
2
+ # Copyright (C) 2008-2009 David Kellum
3
+ #
4
+ # rjack-logback is free software: you can redistribute it and/or
5
+ # modify it under the terms of either of following licenses:
6
+ #
7
+ # GNU Lesser General Public License v3 or later
8
+ # Eclipse Public License v1.0
9
+ #
10
+ # rjack-logback is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ #++
14
+
15
+ module RJack
16
+ module Logback
17
+ # Logback java version
18
+ LOGBACK_VERSION = '0.9.18'
19
+
20
+ # Logback gem version
21
+ VERSION = LOGBACK_VERSION + '.1'
22
+
23
+ LOGBACK_DIR = File.dirname(__FILE__) # :nodoc:
24
+ end
25
+ end
data/pom.xml ADDED
@@ -0,0 +1,51 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2
+
3
+ <modelVersion>4.0.0</modelVersion>
4
+ <groupId>rjack</groupId>
5
+ <artifactId>rjack-logback</artifactId>
6
+ <packaging>pom</packaging>
7
+ <version>1.0</version>
8
+ <name>Logback Assembly for Gem</name>
9
+
10
+ <dependencies>
11
+
12
+ <dependency>
13
+ <groupId>ch.qos.logback</groupId>
14
+ <artifactId>logback-classic</artifactId>
15
+ <version>0.9.18</version>
16
+ <scope>runtime</scope>
17
+ </dependency>
18
+
19
+ <dependency>
20
+ <groupId>ch.qos.logback</groupId>
21
+ <artifactId>logback-access</artifactId>
22
+ <version>0.9.18</version>
23
+ <scope>runtime</scope>
24
+ </dependency>
25
+
26
+ </dependencies>
27
+
28
+ <build>
29
+ <plugins>
30
+ <plugin>
31
+ <artifactId>maven-assembly-plugin</artifactId>
32
+ <configuration>
33
+ <descriptors>
34
+ <descriptor>assembly.xml</descriptor>
35
+ </descriptors>
36
+ <tarLongFileMode>gnu</tarLongFileMode>
37
+ </configuration>
38
+ <executions>
39
+ <execution>
40
+ <id>assembly</id>
41
+ <phase>package</phase>
42
+ <goals>
43
+ <goal>attached</goal>
44
+ </goals>
45
+ </execution>
46
+ </executions>
47
+ </plugin>
48
+ </plugins>
49
+ </build>
50
+
51
+ </project>
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env jruby
2
+ #--
3
+ # Copyright (C) 2008-2009 David Kellum
4
+ #
5
+ # rjack-logback is free software: you can redistribute it and/or
6
+ # modify it under the terms of either of following licenses:
7
+ #
8
+ # GNU Lesser General Public License v3 or later
9
+ # Eclipse Public License v1.0
10
+ #
11
+ # rjack-logback is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+ #++
15
+
16
+ require 'rubygems'
17
+ gem( 'rjack-slf4j', '~> 1.5.8' )
18
+ require 'rjack-slf4j'
19
+
20
+ $LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
21
+ require 'rjack-logback'
22
+
23
+ require 'rjack-slf4j/mdc'
24
+
25
+ # Test load works
26
+ require 'rjack-logback/access'
27
+
28
+ require 'test/unit'
29
+
30
+ class TestAppender
31
+ import 'ch.qos.logback.core.Appender'
32
+ include Appender
33
+
34
+ attr_reader :count, :last
35
+ attr_writer :layout
36
+
37
+ def initialize
38
+ reset
39
+ end
40
+
41
+ def doAppend( event )
42
+ @count += 1
43
+ @last = event
44
+ @last = @layout.nil? ? event : @layout.doLayout( event )
45
+ end
46
+
47
+ def start; end
48
+ def stop; end
49
+
50
+ def reset
51
+ @count = 0
52
+ @last = nil
53
+ @layout = nil
54
+ end
55
+ end
56
+
57
+ class TestLevelSet < Test::Unit::TestCase
58
+
59
+ def setup
60
+ @appender = TestAppender.new
61
+ Logback.configure do
62
+ Logback.root.add_appender( @appender )
63
+ end
64
+ @log = SLF4J[ "my.app" ]
65
+ end
66
+
67
+ def teardown
68
+ @appender.reset()
69
+ end
70
+
71
+ def test_below_level
72
+ Logback.root.level = Logback::ERROR
73
+ assert( ! @log.debug? )
74
+ @log.debug( "not logged" )
75
+ @log.debug { "also not logged" }
76
+ assert_equal( 0, @appender.count )
77
+ end
78
+
79
+ def test_above_level
80
+ Logback.root.level = Logback::TRACE
81
+ assert( @log.trace? )
82
+ @log.trace( "logged" )
83
+ assert_equal( 1, @appender.count )
84
+ assert_equal( Logback::TRACE, @appender.last.level )
85
+ assert_equal( "logged", @appender.last.message )
86
+ end
87
+
88
+ def test_override_level
89
+ Logback.root.level = Logback::ERROR
90
+ Logback[ "my" ].level = Logback::WARN
91
+ assert( @log.warn? )
92
+ @log.warn( "override" )
93
+ assert_equal( Logback::WARN, @appender.last.level )
94
+ assert_equal( 1, @appender.count )
95
+
96
+ # Unset override
97
+ Logback[ "my" ].level = nil
98
+ assert( ! @log.warn? )
99
+ end
100
+
101
+ end
102
+
103
+ class TestConfigure < Test::Unit::TestCase
104
+
105
+ def test_file_appender_config
106
+ log_file = "./test_appends.test_file_appender.log"
107
+
108
+ Logback.configure do
109
+ appender = Logback::FileAppender.new( log_file, false ) do |a|
110
+ a.layout = Logback::PatternLayout.new( "%level-%msg" )
111
+ a.immediate_flush = true
112
+ a.encoding = "ISO-8859-1"
113
+ end
114
+ Logback.root.add_appender( appender )
115
+ end
116
+ log = SLF4J[ self.class.name ]
117
+ log.debug( "write to file" )
118
+ assert( File.file?( log_file ) )
119
+ assert( File.stat( log_file ).size > 0 )
120
+ assert_equal( 1, File.delete( log_file ) )
121
+ end
122
+
123
+ def test_pattern_config
124
+ appender = TestAppender.new
125
+ Logback.configure do
126
+ appender.layout = Logback::PatternLayout.new( "%level-%msg" )
127
+ Logback.root.add_appender( appender )
128
+ end
129
+
130
+ log = SLF4J[ self.class.name ]
131
+ log.info( "message" )
132
+ assert_equal( 1, appender.count )
133
+ assert_equal( "INFO-message", appender.last )
134
+ end
135
+
136
+ def test_console_config
137
+ log_name = "#{self.class.name}.#{self.method_name}"
138
+ appender = TestAppender.new
139
+ Logback.configure do
140
+ console = Logback::ConsoleAppender.new do |a|
141
+ a.immediate_flush = true
142
+ a.encoding = "UTF-8"
143
+ a.target = "System.out"
144
+ end
145
+ Logback.root.add_appender( console )
146
+ Logback[ log_name ].add_appender( appender )
147
+ end
148
+
149
+ Logback[ log_name ].level = Logback::DEBUG
150
+ Logback[ log_name ].additive = false
151
+ log = SLF4J[ log_name ]
152
+ log.debug( "test write to console" )
153
+ assert_equal( 1, appender.count )
154
+ end
155
+
156
+ def test_config_console
157
+ Logback.config_console( :mdc => [ :key1, :key2 ], :mdc_width => 11 )
158
+ log = SLF4J[ self.class ]
159
+ log.info "without"
160
+ SLF4J::MDC[ :key1 ] = "val1"
161
+ log.info "with 1"
162
+ SLF4J::MDC[ :key2 ] = "val2"
163
+ log.info "with 2"
164
+ end
165
+
166
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rjack-logback
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.18.1
5
+ platform: java
6
+ authors:
7
+ - David Kellum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-06 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rjack-slf4j
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.8
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rjack-tarpit
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ version:
35
+ description: |-
36
+ The Logback ruby gem packages the Logback[http://logback.qos.ch/] java log
37
+ writer, and provides a JRuby facade for programmatic Logback
38
+ setup. Logback implements the SLF4J[http://www.slf4j.org/] SPI
39
+ packaged in the {slf4j gem}[http://rjack.rubyforge.org/slf4j/].
40
+ email:
41
+ - dek-oss@gravitext.com
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ extra_rdoc_files:
47
+ - Manifest.txt
48
+ - README.rdoc
49
+ - History.rdoc
50
+ files:
51
+ - Manifest.static
52
+ - Manifest.txt
53
+ - README.rdoc
54
+ - History.rdoc
55
+ - Rakefile
56
+ - pom.xml
57
+ - assembly.xml
58
+ - lib/rjack-logback/base.rb
59
+ - lib/rjack-logback.rb
60
+ - lib/rjack-logback/access.rb
61
+ - test/test_logback.rb
62
+ - lib/rjack-logback/logback-access-0.9.18.jar
63
+ - lib/rjack-logback/logback-classic-0.9.18.jar
64
+ - lib/rjack-logback/logback-core-0.9.18.jar
65
+ has_rdoc: true
66
+ homepage: http://rjack.rubyforge.org
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --main
72
+ - README.rdoc
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: rjack
90
+ rubygems_version: 1.3.5
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: The Logback ruby gem packages the Logback[http://logback.qos.ch/] java log writer, and provides a JRuby facade for programmatic Logback setup
94
+ test_files:
95
+ - test/test_logback.rb