rjack-slf4j 1.5.11.0-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,42 @@
1
+ === 1.5.11.0 (2010-3-6)
2
+ * Upgraded to SLF4J 1.5.11
3
+ * Set gem platform to java
4
+ * SLF4J.ruby_to_java_logger_name renamed/aliased SLF4J.to_log_name
5
+ * Upgraded to tarpit ~> 1.2.0
6
+
7
+ === 1.5.10.0 (2009-12-19)
8
+ * Upgraded to SLF4J 1.5.10
9
+ * Upgraded to tarpit-1.1.0 (gemcutter)
10
+
11
+ === 1.5.8.1 (2009-10-10)
12
+ * Renamed gem rjack-slf4j and as module RJack::SLF4J (with ::SLF4J
13
+ alias kept for backward compatibility.)
14
+ * Use rjack-tarpit for build.
15
+ * Upgraded to SLF4J 1.5.8
16
+ * Added support for logging exceptions from ruby, with special
17
+ handling of NativeException#cause
18
+ * Added support for converting from ruby style "Module::Class" to java
19
+ "module.Class" name in SLF4J::Logger.new
20
+ * Added SLF4J::MDC (Mapped Diagnostic Context) support module
21
+ * Added Logger.java_logger access
22
+
23
+ === 1.5.6.3 (2009-4-25)
24
+ * Added SLF4J::JUL for controlling java.util.logging, including
25
+ JUL.replace_root_handlers which removes all existing handlers and
26
+ add SLF4JBridgeHandler for exclusive routing to SLF4J for use with
27
+ 'jul-to-slf4j'.
28
+ * Added require 'slf4j' to each adapter loader.
29
+ * Use rdoc 2.4.3 and hoe 1.12.2 for build.
30
+
31
+ === 1.5.6.2 (2009-4-4)
32
+ * Fixed previously lost rdoc due to base vs slf4j.rb manifest order.
33
+
34
+ === 1.5.6.1 (2008-12-6)
35
+ * Upgraded to SLF4J 1.5.6
36
+ * SLF4JBase -rename-> SLF4J
37
+
38
+ === 1.5.5.1 (2008-11-1)
39
+ * Upgraded to SLF4J 1.5.5
40
+
41
+ === 1.5.3.1 (2008-10-8)
42
+ * Initial release based on SLF4J 1.5.3
data/Manifest.static ADDED
@@ -0,0 +1,13 @@
1
+ Manifest.static
2
+ Manifest.txt
3
+ README.rdoc
4
+ History.rdoc
5
+ Rakefile
6
+ pom.xml
7
+ assembly.xml
8
+ lib/rjack-slf4j/base.rb
9
+ lib/rjack-slf4j.rb
10
+ lib/rjack-slf4j/jul-to-slf4j.rb
11
+ lib/rjack-slf4j/jul.rb
12
+ lib/rjack-slf4j/mdc.rb
13
+ test/test_slf4j.rb
data/Manifest.txt ADDED
@@ -0,0 +1,29 @@
1
+ Manifest.static
2
+ Manifest.txt
3
+ README.rdoc
4
+ History.rdoc
5
+ Rakefile
6
+ pom.xml
7
+ assembly.xml
8
+ lib/rjack-slf4j/base.rb
9
+ lib/rjack-slf4j.rb
10
+ lib/rjack-slf4j/jul-to-slf4j.rb
11
+ lib/rjack-slf4j/jul.rb
12
+ lib/rjack-slf4j/mdc.rb
13
+ test/test_slf4j.rb
14
+ lib/rjack-slf4j/jcl-over-slf4j.rb
15
+ lib/rjack-slf4j/jcl.rb
16
+ lib/rjack-slf4j/jdk14.rb
17
+ lib/rjack-slf4j/log4j-over-slf4j.rb
18
+ lib/rjack-slf4j/log4j12.rb
19
+ lib/rjack-slf4j/nop.rb
20
+ lib/rjack-slf4j/simple.rb
21
+ lib/rjack-slf4j/jcl-over-slf4j-1.5.11.jar
22
+ lib/rjack-slf4j/jul-to-slf4j-1.5.11.jar
23
+ lib/rjack-slf4j/log4j-over-slf4j-1.5.11.jar
24
+ lib/rjack-slf4j/slf4j-api-1.5.11.jar
25
+ lib/rjack-slf4j/slf4j-jcl-1.5.11.jar
26
+ lib/rjack-slf4j/slf4j-jdk14-1.5.11.jar
27
+ lib/rjack-slf4j/slf4j-log4j12-1.5.11.jar
28
+ lib/rjack-slf4j/slf4j-nop-1.5.11.jar
29
+ lib/rjack-slf4j/slf4j-simple-1.5.11.jar
data/README.rdoc ADDED
@@ -0,0 +1,70 @@
1
+ = rjack-slf4j
2
+
3
+ * http://rjack.rubyforge.org
4
+ * http://rubyforge.org/projects/rjack
5
+
6
+ == Description
7
+
8
+ A JRuby adaption and gem packaging of the
9
+ {Simple Logging Facade for Java}[http://www.slf4j.org/].
10
+ Provides all jar dependencies and a Ruby Logger compatible
11
+ facade.
12
+
13
+ SLF4J is a java logging abstraction and set of adapters to various
14
+ concrete logging implementations and legacy logging APIs. The slf4j
15
+ gem adds a ruby core Logger compatible facade to SLF4J, and makes any
16
+ needed adapters available to JRuby applications. This makes it
17
+ possible to unify and control logging output of both java and ruby
18
+ components in a JRuby application.
19
+
20
+ == Features
21
+
22
+ * The complete set of SLF4J jars with ruby 'require' based selection
23
+ of input and output adapters.
24
+ * A Ruby core Logger compatible SLF4J::Logger, allowing ruby code to
25
+ log through SLF4J.
26
+
27
+ == Synopsis
28
+
29
+ require 'rjack-slf4j'
30
+ require 'rjack-slf4j/simple'
31
+
32
+ log = RJack::SLF4J[ "my.app.logger" ]
33
+ log.info "Hello World!"
34
+
35
+ == License
36
+
37
+ === rjack-slf4j gem
38
+
39
+ Copyright (c) 2008-2009 David Kellum
40
+ All rights reserved.
41
+
42
+ The SLF4J ruby wrapper and gem packaging is released under the same
43
+ license terms as the SLF4J java binaries, see below. Note that these
44
+ license terms are identical to the
45
+ {MIT License}[http://en.wikipedia.org/wiki/MIT_License] and deemed
46
+ compatible with GPL and the Apache Software License.
47
+
48
+ === SLF4J (java)
49
+
50
+ Copyright (c) 2004-2008 QOS.ch
51
+ All rights reserved.
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ "Software"), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
67
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
68
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
69
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
70
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,88 @@
1
+ # -*- ruby -*-
2
+ #--
3
+ # Copyright (C) 2008-2009 David Kellum
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person
6
+ # obtaining a copy of this software and associated documentation files
7
+ # (the "Software"), to deal in the Software without restriction,
8
+ # including without limitation the rights to use, copy, modify, merge,
9
+ # publish, distribute, sublicense, and/or sell copies of the Software,
10
+ # and to permit persons to whom the Software is furnished to do so,
11
+ # subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #++
25
+
26
+ $LOAD_PATH << './lib'
27
+ require 'rjack-slf4j/base'
28
+
29
+ require 'rubygems'
30
+ gem 'rjack-tarpit', '~> 1.2.0'
31
+ require 'rjack-tarpit'
32
+
33
+ t = RJack::TarPit.new( 'rjack-slf4j', RJack::SLF4J::VERSION, :java_platform )
34
+
35
+ t.specify do |h|
36
+ h.developer( "David Kellum", "dek-oss@gravitext.com" )
37
+ h.rubyforge_name = "rjack"
38
+ h.remote_rdoc_dir = "slf4j"
39
+ end
40
+
41
+ loaders =
42
+ begin
43
+ l = RJack::SLF4J::ADAPTERS.flatten.compact
44
+ l.delete( "jul-to-slf4j" ) # exception: maintained as source
45
+ l
46
+ end
47
+
48
+ t.generated_files = loaders.map { |adp| "lib/#{t.name}/#{adp}.rb" }
49
+
50
+ t.jars =
51
+ begin
52
+ j = [ 'slf4j-api' ]
53
+ j += RJack::SLF4J::ADAPTERS.map { |i,o| [ i, "slf4j-#{o}" ] }.flatten.compact
54
+ j.map { |n| "#{n}-#{RJack::SLF4J::SLF4J_VERSION}.jar" }
55
+ end
56
+
57
+ file 'Manifest.txt' => [ "lib/#{t.name}/base.rb" ]
58
+
59
+ t.assembly_version = 1.0
60
+
61
+ task :check_pom_deps do
62
+ t.test_line_match( 'pom.xml',
63
+ %r[<version>#{RJack::SLF4J::SLF4J_VERSION}</version>] )
64
+ end
65
+
66
+ task :check_history_version do
67
+ t.test_line_match( 'History.rdoc', /^==/, / #{t.version} / )
68
+ end
69
+ task :check_history_date do
70
+ t.test_line_match( 'History.rdoc', /^==/, /\([0-9\-]+\)$/ )
71
+ end
72
+
73
+ task :gem => [ :check_pom_deps, :check_history_version ]
74
+ task :tag => [ :check_pom_deps, :check_history_version, :check_history_date ]
75
+ task :push => [ :check_history_date ]
76
+
77
+ t.define_tasks
78
+
79
+ loaders.each do |adapter|
80
+ file "lib/#{t.name}/#{adapter}.rb" => [ "lib/#{t.name}/base.rb", 'Rakefile' ] do
81
+ open( "lib/#{t.name}/#{adapter}.rb", 'w' ) do |out|
82
+ out.write <<END
83
+ require 'rjack-slf4j'
84
+ RJack::SLF4J.require_adapter( '#{adapter}' )
85
+ END
86
+ end
87
+ end
88
+ end
data/assembly.xml ADDED
@@ -0,0 +1,24 @@
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>org.slf4j:slf4j-api</include>
11
+ <include>org.slf4j:jcl-over-slf4j</include>
12
+ <include>org.slf4j:jul-to-slf4j</include>
13
+ <include>org.slf4j:log4j-over-slf4j</include>
14
+ <include>org.slf4j:slf4j-jcl</include>
15
+ <include>org.slf4j:slf4j-jdk14</include>
16
+ <include>org.slf4j:slf4j-log4j12</include>
17
+ <include>org.slf4j:slf4j-nop</include>
18
+ <include>org.slf4j:slf4j-simple</include>
19
+ </includes>
20
+ </dependencySet>
21
+
22
+ </dependencySets>
23
+
24
+ </assembly>
@@ -0,0 +1,42 @@
1
+ #--
2
+ # Copyright (C) 2008-2009 David Kellum
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #++
24
+
25
+ module RJack
26
+ module SLF4J
27
+
28
+ # SLF4J-java version
29
+ SLF4J_VERSION = '1.5.11'
30
+ # SLF4J gem version
31
+ VERSION = SLF4J_VERSION + '.0'
32
+
33
+ SLF4J_DIR = File.dirname(__FILE__) # :nodoc:
34
+
35
+ # :input :output (jar with slf4j- prefix)
36
+ ADAPTERS = [ [ "jul-to-slf4j", "jdk14" ],
37
+ [ "jcl-over-slf4j", "jcl" ],
38
+ [ "log4j-over-slf4j", "log4j12" ],
39
+ [ nil, "nop" ],
40
+ [ nil, "simple" ] ] # :nodoc:
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ require 'rjack-slf4j'
2
+ RJack::SLF4J.require_adapter( 'jcl-over-slf4j' )
@@ -0,0 +1,2 @@
1
+ require 'rjack-slf4j'
2
+ RJack::SLF4J.require_adapter( 'jcl' )
@@ -0,0 +1,2 @@
1
+ require 'rjack-slf4j'
2
+ RJack::SLF4J.require_adapter( 'jdk14' )
@@ -0,0 +1,20 @@
1
+ require 'rjack-slf4j'
2
+ require 'rjack-slf4j/jul'
3
+
4
+ RJack::SLF4J.require_adapter( 'jul-to-slf4j' )
5
+
6
+ module RJack::SLF4J::JUL
7
+
8
+ # Replace any existing configured root java.util.Logger Handlers with
9
+ # the org.slf4j.bridge.SLF4JBridgeHandler
10
+ def self.replace_root_handlers
11
+ root_logger = root
12
+ root_logger.handlers.each do |handler|
13
+ root_logger.remove_handler( handler )
14
+ end
15
+ handler = Java::org.slf4j.bridge.SLF4JBridgeHandler.new
16
+
17
+ root_logger.add_handler( handler )
18
+ end
19
+
20
+ end
@@ -0,0 +1,77 @@
1
+ #--
2
+ # Copyright (C) 2009 David Kellum
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #++
24
+
25
+ require 'rjack-slf4j'
26
+ require 'java'
27
+
28
+ # Utilities for finer grain control of the JDK java.util.logging
29
+ # (JUL). In particular, unlike other logging API's reimplemented by
30
+ # slf4j adapters, JUL log levels remain significant for enabling output
31
+ # or avoiding log message generation cycles. For a particular
32
+ # level to be output, both JUL and the destination SLF4J output adapter
33
+ # must enable it.
34
+ #
35
+ # == Usage
36
+ #
37
+ # Adjust JUL levels (in conjunction with 'slf4j/jul-to-slf4j' or
38
+ # 'slf4j/jdk14', see SLF4J.)
39
+ #
40
+ # require 'rjack-slf4j/jul'
41
+ # SLF4J::JUL[ "my.jul.logger" ].level = SLF4J::JUL::FINER
42
+ #
43
+ # Direct all output to SLF4J (output adapter != 'jdk14')
44
+ #
45
+ # require 'rjack-slf4j/jul-to-slf4j'
46
+ # RJack::SLF4J::JUL.replace_root_handlers
47
+ #
48
+ module RJack::SLF4J::JUL
49
+ LogManager = Java::java.util.logging.LogManager
50
+ Logger = Java::java.util.logging.Logger
51
+ Level = Java::java.util.logging.Level
52
+
53
+ SEVERE = Level::SEVERE
54
+ WARNING = Level::WARNING
55
+ INFO = Level::INFO
56
+ CONFIG = Level::CONFIG
57
+ FINE = Level::FINE
58
+ FINER = Level::FINER
59
+ FINEST = Level::FINEST
60
+ ALL = Level::ALL
61
+
62
+ # Global java.util.logging.LogManager reset: close any handlers and
63
+ # set root level to INFO.
64
+ def self.reset
65
+ LogManager.log_manager.reset
66
+ end
67
+
68
+ # Get java.util.logging.Logger by name (responds to level=, etc.)
69
+ def self.[]( name )
70
+ Logger.get_logger( name )
71
+ end
72
+
73
+ # Get the root logger (empty string name)
74
+ def self.root
75
+ Logger.get_logger( "" )
76
+ end
77
+ end
@@ -0,0 +1,2 @@
1
+ require 'rjack-slf4j'
2
+ RJack::SLF4J.require_adapter( 'log4j-over-slf4j' )
@@ -0,0 +1,2 @@
1
+ require 'rjack-slf4j'
2
+ RJack::SLF4J.require_adapter( 'log4j12' )
@@ -0,0 +1,47 @@
1
+ #--
2
+ # Copyright (C) 2008-2009 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'rjack-slf4j'
18
+
19
+ module RJack::SLF4J
20
+
21
+ # Mapped Diagnostic Context support module
22
+ #
23
+ # Note that this optional module can only be loaded after a output
24
+ # adapter has been loaded. Otherwise the following output is
25
+ # printed and Exception will be thrown:
26
+ #
27
+ # SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
28
+ # SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
29
+ # java.lang.NoClassDefFoundError: org/slf4j/impl/StaticMDCBinder
30
+ #
31
+ module MDC
32
+
33
+ # Get value associated with key, or nil.
34
+ def self.[]( key )
35
+ org.slf4j.MDC::get( key.to_s )
36
+ end
37
+
38
+ # Associate val with key, or remove key is value is nil.
39
+ def self.[]=( key, val )
40
+ if val
41
+ org.slf4j.MDC::put( key.to_s, val.to_s )
42
+ else
43
+ org.slf4j.MDC::remove( key.to_s )
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,2 @@
1
+ require 'rjack-slf4j'
2
+ RJack::SLF4J.require_adapter( 'nop' )
@@ -0,0 +1,2 @@
1
+ require 'rjack-slf4j'
2
+ RJack::SLF4J.require_adapter( 'simple' )
@@ -0,0 +1,265 @@
1
+ #--
2
+ # Copyright (C) 2008-2009 David Kellum
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #++
24
+
25
+ require 'rjack-slf4j/base'
26
+ require 'java'
27
+
28
+ # Backward compatibility for top level ::SLF4J module
29
+ SLF4J = RJack::SLF4J
30
+
31
+ module RJack
32
+
33
+ # Wrapper and core Logger compatible adapter for the
34
+ # SLF4J[http://www.slf4j.org/] logging interface.
35
+ #
36
+ # == Usage
37
+ #
38
+ # require 'rjack-slf4j'
39
+ #
40
+ # log = RJack::SLF4J[ "my.app.logger" ]
41
+ # log.info "Hello World!"
42
+ #
43
+ # == Adapters
44
+ #
45
+ # An output adapter must be required before the first log call. All
46
+ # of the following output adapters are available via +require+ from
47
+ # the slf4j gem:
48
+ #
49
+ # require 'rjack-slf4j/jcl' # Output to Jakarta Commons Logging
50
+ # require 'rjack-slf4j/jdk14' # JDK java.util.logging (JUL)
51
+ # require 'rjack-slf4j/log4j12' # Log4j (provided elsewhere)
52
+ # require 'rjack-slf4j/nop' # NOP null logger (provided)
53
+ # require 'rjack-slf4j/simple' # Simple logger (provided)
54
+ #
55
+ # The rjack-logback[http://rjack.rubyforge.org/logback] gem may
56
+ # also be be used as the output adapter:
57
+ #
58
+ # require 'rjack-logback'
59
+ #
60
+ # The first loaded output adapter wins (as with multiple adapters on
61
+ # the classpath). A warning will be logged to "slf4j" if an attempt is
62
+ # made to require a second output adapter.
63
+ #
64
+ # The following input adapters will intercept JCL, java.util.logging
65
+ # (JUL), or log4j log output and direct it through SLF4J:
66
+ #
67
+ # require 'rjack-slf4j/jcl-over-slf4j' # Route Jakarta Commons Logging to SLF4J
68
+ # require 'rjack-slf4j/log4j-over-slf4j' # Log4j to SLF4J
69
+ #
70
+ # require 'rjack-slf4j/jul-to-slf4j' # JDK java.util.logging (JUL) to SLF4J
71
+ # RJack::SLF4J::JUL.replace_root_handlers # Special case setup for JUL
72
+ #
73
+ # Multiple input adapters may be require'd. However, a RuntimeError
74
+ # will be raised in the attempt to require both an output adapter and
75
+ # input adapter from/to the same interface, for example
76
+ # 'rjack-slf4j/jcl-over-slf4j' and 'rjack-slf4j/jcl', which would otherwise cause
77
+ # a circular logging loop (and stack overflow.)
78
+ #
79
+ # Adapter names match the corresponding SLF4J jars.
80
+ #
81
+ module SLF4J
82
+
83
+ # Require an adapter by name (add the jar to classpath)
84
+ # This is normally done via require 'slf4j/_name_'
85
+ def self.require_adapter( name )
86
+ row = ADAPTERS.assoc( name )
87
+ if row
88
+ name,ban = row
89
+ output = false
90
+ else
91
+ row = ADAPTERS.rassoc( name )
92
+ ban,name = row
93
+ output = true
94
+ end
95
+
96
+ if @@loaded[ ban ]
97
+ raise "Illegal attempt to load '#{name}' when '#{ban}' is loaded."
98
+ end
99
+
100
+ if output
101
+ if ! @@output_name.nil? && name != @@output_name
102
+ logger("slf4j").warn do
103
+ "Ignoring attempt to load #{name} after #{@@output_name} already loaded."
104
+ end
105
+ return
106
+ end
107
+ if java.lang.Thread::current_thread.context_class_loader != @@api_loader
108
+ $stderr.puts( "WARNING: Attempting to load #{name} in child class" +
109
+ " loader of slf4j-api.jar loader." )
110
+ end
111
+ require_jar( 'slf4j-' + name )
112
+ @@output_name = name
113
+ else
114
+ require_jar( name )
115
+ end
116
+
117
+ @@loaded[ name ] = true
118
+ end
119
+
120
+ def self.require_jar( name ) # :nodoc:
121
+ require File.join( SLF4J_DIR, "#{name}-#{ SLF4J_VERSION }.jar" )
122
+ end
123
+
124
+ require_jar 'slf4j-api'
125
+
126
+ @@api_loader = org.slf4j.ILoggerFactory.java_class.class_loader
127
+ @@loaded = {}
128
+ @@output_name = nil
129
+
130
+ # Output adapter name if one has been added, or nil.
131
+ def self.output_name
132
+ @@output_name
133
+ end
134
+
135
+ # SLF4J severity levels
136
+ LEVELS = %w{ trace debug info warn error }
137
+
138
+ # Return a java style class name, suitable as a logger name, from the
139
+ # given ruby class or module, i.e:
140
+ #
141
+ # to_log_name( Foo::Bar::Baz ) --> "foo.bar.Baz"
142
+ #
143
+ def self.to_log_name( clz )
144
+ clz.name.gsub( /::/, '.' ).gsub( /([^\.]+)\./ ) { |m| m.downcase }
145
+ end
146
+
147
+ class << self
148
+ alias ruby_to_java_logger_name to_log_name
149
+ end
150
+
151
+ # Logger compatible facade over org.slf4j.Logger
152
+ #
153
+ # === Generated Methods
154
+ #
155
+ # Corresponding methods are generated for each of the SLF4J levels:
156
+ #
157
+ # * trace
158
+ # * debug
159
+ # * info
160
+ # * warn
161
+ # * error
162
+ # * fatal (alias to error)
163
+ #
164
+ # These have the form (using _info_ as example):
165
+ #
166
+ # log = Logger.new( "name" )
167
+ # log.info? # Is this level enabled for logging?
168
+ # log.info( "message" ) # Log message
169
+ # log.info { "message" } # Execute block if enabled
170
+ # and log returned value
171
+ # log.info( "message", ex ) # Log message with exception message/stack trace
172
+ # log.info( ex ) { "message" } # Log message with exception message/stack trace
173
+ # log.info( ex ) # Log exception with default "Exception:" message
174
+ #
175
+ # Note that the exception variants are aware of JRuby's
176
+ # NativeException class (a wrapped java exception) and will log
177
+ # using the Java ex.cause in this case.
178
+ #
179
+ class Logger
180
+ attr_reader :name
181
+
182
+ # Create new or find existing Logger by name. If name is a Module (Class, etc.)
183
+ # then use SLF4J.to_log_name( name ) as the name
184
+ #
185
+ # Note that loggers are arranged in a hiearchy by dot '.' name
186
+ # notation using java package/class name conventions:
187
+ #
188
+ # * "pmodule"
189
+ # * "pmodule.cmodule."
190
+ # * "pmodule.cmodule.ClassName"
191
+ #
192
+ # Which enables hierarchical level setting and abbreviation in some output adapters.
193
+ #
194
+ def initialize( name )
195
+ @name = name.is_a?( Module ) ? SLF4J.to_log_name( name ) : name
196
+ @logger = org.slf4j.LoggerFactory.getLogger( @name )
197
+ end
198
+
199
+ # Return underlying org.slf4j.Logger
200
+ def java_logger
201
+ @logger
202
+ end
203
+
204
+ # Define logging methods for each level: debug(), error(), etc.
205
+ LEVELS.each do |lvl|
206
+ module_eval( %Q{
207
+
208
+ def #{lvl}?
209
+ @logger.is#{lvl.capitalize}Enabled
210
+ end
211
+
212
+ def #{lvl}( msg=nil, ex=nil )
213
+ if msg.is_a?( Exception ) && ex.nil?
214
+ msg, ex = "Exception:", msg
215
+ end
216
+ msg = yield if ( block_given? && #{lvl}? )
217
+ if msg
218
+ if ex
219
+ #{lvl}_ex( msg, ex )
220
+ else
221
+ @logger.#{lvl}( msg.to_s )
222
+ end
223
+ end
224
+ end
225
+
226
+ def #{lvl}_ex( msg, ex )
227
+ if ex.is_a?( NativeException )
228
+ @logger.#{lvl}( msg.to_s, ex.cause )
229
+ elsif #{lvl}?
230
+ log = msg.to_s
231
+ log << '\n'
232
+ log << ex.class.name << ': ' << ex.message << '\n'
233
+ ex.backtrace.each do |b|
234
+ log << '\t' << b << '\n'
235
+ end
236
+ @logger.#{lvl}( log )
237
+ end
238
+ end
239
+
240
+ } )
241
+ end
242
+
243
+ # Alias fatal to error for Logger compatibility
244
+ alias_method :fatal, :error
245
+ alias_method :fatal?, :error?
246
+ end
247
+
248
+ # Get Logger by name
249
+ def logger( name = self.class.name )
250
+ Logger.new( name )
251
+ end
252
+ module_function :logger
253
+
254
+ # Synonym for Logger.new( name )
255
+ def self.[]( name )
256
+ Logger.new( name )
257
+ end
258
+
259
+ # The ILoggerFactory instance if an output adapter has been loaded
260
+ def self.linked_factory
261
+ org.slf4j.LoggerFactory.getILoggerFactory
262
+ end
263
+
264
+ end
265
+ end
data/pom.xml ADDED
@@ -0,0 +1,104 @@
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-slf4j</artifactId>
6
+ <packaging>pom</packaging>
7
+ <version>1.0</version>
8
+ <name>SLF4J assembly</name>
9
+
10
+ <dependencies>
11
+
12
+ <dependency>
13
+ <groupId>org.slf4j</groupId>
14
+ <artifactId>slf4j-api</artifactId>
15
+ <version>1.5.11</version>
16
+ </dependency>
17
+
18
+ <dependency>
19
+ <groupId>org.slf4j</groupId>
20
+ <artifactId>jcl-over-slf4j</artifactId>
21
+ <version>1.5.11</version>
22
+ <scope>runtime</scope>
23
+ </dependency>
24
+
25
+ <dependency>
26
+ <groupId>org.slf4j</groupId>
27
+ <artifactId>jul-to-slf4j</artifactId>
28
+ <version>1.5.11</version>
29
+ <scope>runtime</scope>
30
+ </dependency>
31
+
32
+ <dependency>
33
+ <groupId>org.slf4j</groupId>
34
+ <artifactId>log4j-over-slf4j</artifactId>
35
+ <version>1.5.11</version>
36
+ <scope>runtime</scope>
37
+ </dependency>
38
+
39
+ <dependency>
40
+ <groupId>org.slf4j</groupId>
41
+ <artifactId>slf4j-jdk14</artifactId>
42
+ <version>1.5.11</version>
43
+ <scope>runtime</scope>
44
+ <optional>true</optional>
45
+ </dependency>
46
+
47
+ <dependency>
48
+ <groupId>org.slf4j</groupId>
49
+ <artifactId>slf4j-log4j12</artifactId>
50
+ <version>1.5.11</version>
51
+ <scope>runtime</scope>
52
+ <optional>true</optional>
53
+ </dependency>
54
+
55
+ <dependency>
56
+ <groupId>org.slf4j</groupId>
57
+ <artifactId>slf4j-jcl</artifactId>
58
+ <version>1.5.11</version>
59
+ <scope>runtime</scope>
60
+ <optional>true</optional>
61
+ </dependency>
62
+
63
+ <dependency>
64
+ <groupId>org.slf4j</groupId>
65
+ <artifactId>slf4j-simple</artifactId>
66
+ <version>1.5.11</version>
67
+ <scope>runtime</scope>
68
+ <optional>true</optional>
69
+ </dependency>
70
+
71
+ <dependency>
72
+ <groupId>org.slf4j</groupId>
73
+ <artifactId>slf4j-nop</artifactId>
74
+ <version>1.5.11</version>
75
+ <scope>runtime</scope>
76
+ <optional>true</optional>
77
+ </dependency>
78
+
79
+ </dependencies>
80
+
81
+ <build>
82
+ <plugins>
83
+ <plugin>
84
+ <artifactId>maven-assembly-plugin</artifactId>
85
+ <configuration>
86
+ <descriptors>
87
+ <descriptor>assembly.xml</descriptor>
88
+ </descriptors>
89
+ <tarLongFileMode>gnu</tarLongFileMode>
90
+ </configuration>
91
+ <executions>
92
+ <execution>
93
+ <id>assembly</id>
94
+ <phase>package</phase>
95
+ <goals>
96
+ <goal>attached</goal>
97
+ </goals>
98
+ </execution>
99
+ </executions>
100
+ </plugin>
101
+ </plugins>
102
+ </build>
103
+
104
+ </project>
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env jruby
2
+ #--
3
+ # Copyright (c) 2008-2009 David Kellum
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person
6
+ # obtaining a copy of this software and associated documentation files
7
+ # (the "Software"), to deal in the Software without restriction,
8
+ # including without limitation the rights to use, copy, modify, merge,
9
+ # publish, distribute, sublicense, and/or sell copies of the Software,
10
+ # and to permit persons to whom the Software is furnished to do so,
11
+ # subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #++
25
+
26
+ $LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
27
+
28
+ require 'rjack-slf4j'
29
+
30
+ # Load jdk14 implementation for testing
31
+ require 'rjack-slf4j/jdk14'
32
+
33
+ # Now safe to load:
34
+ require 'rjack-slf4j/mdc'
35
+
36
+ # Load these only to confirm loading works
37
+ require 'rjack-slf4j/jcl-over-slf4j'
38
+ require 'rjack-slf4j/log4j-over-slf4j'
39
+
40
+ require 'test/unit'
41
+
42
+ class TestHandler < java.util.logging.Handler
43
+ attr_accessor :count, :last
44
+
45
+ def initialize
46
+ reset
47
+ end
48
+
49
+ def flush; end
50
+ def close; end
51
+
52
+ def publish( record )
53
+ @count += 1
54
+ @last = record
55
+ end
56
+
57
+ def reset
58
+ @count = 0
59
+ @last = nil
60
+ end
61
+ end
62
+
63
+ module Foo
64
+ module Bar
65
+ class Baz
66
+ end
67
+ end
68
+ end
69
+
70
+ class TestSlf4j < Test::Unit::TestCase
71
+
72
+ JdkLogger = java.util.logging.Logger
73
+
74
+ def setup
75
+ @handler = TestHandler.new
76
+ @jdk_logger = JdkLogger.getLogger ""
77
+ @jdk_logger.addHandler @handler
78
+ @jdk_logger.level = java.util.logging.Level::INFO
79
+ @log = SLF4J[ "my.app" ]
80
+ end
81
+
82
+ def teardown
83
+ @handler.reset
84
+ end
85
+
86
+ def test_logger
87
+ assert !@log.trace?
88
+ @log.trace( "not written" )
89
+ assert !@log.debug?
90
+ @log.debug { "also not written" }
91
+ assert @log.info?
92
+ @log.info { "test write info" }
93
+ assert @log.warn?
94
+ @log.warn { "test write warning" }
95
+ assert @log.error?
96
+ @log.error( "test write error" )
97
+ assert @log.fatal?
98
+ @log.fatal { "test write fatal --> error" }
99
+ assert_equal( 4, @handler.count )
100
+ end
101
+
102
+ def test_native_exception
103
+ jlist = Java::java.util.ArrayList.new
104
+ jlist.add( 33 )
105
+ ex = nil
106
+ begin
107
+ jlist.get( 666 ) # IndexOutOfBoundsException
108
+ rescue Java::java.lang.IndexOutOfBoundsException => x
109
+ ex = x
110
+ @log.error( "test java exception", x )
111
+ end
112
+ assert_equal( 1, @handler.count )
113
+ assert_same( ex.cause, @handler.last.thrown )
114
+ end
115
+
116
+ def test_ruby_exception
117
+ begin
118
+ 0/0 # ZeroDivisionError
119
+ rescue ZeroDivisionError => x
120
+ @log.error( x )
121
+ end
122
+ assert_equal( 1, @handler.count )
123
+ end
124
+
125
+ def test_ruby_exception_block
126
+ begin
127
+ 0/0 # ZeroDivisionError
128
+ rescue ZeroDivisionError => x
129
+ @log.error( x ) { "ruby exception" }
130
+ end
131
+ assert_equal( 1, @handler.count )
132
+ end
133
+
134
+ def test_to_log_name
135
+ assert_equal( "foo.bar.Baz",
136
+ SLF4J.to_log_name( Foo::Bar::Baz ) )
137
+ assert_equal( "foo.bar.Baz", SLF4J[ Foo::Bar::Baz ].name )
138
+ end
139
+
140
+ def test_circular_ban
141
+ assert_raise( RuntimeError ) do
142
+ require 'rjack-slf4j/jul-to-slf4j'
143
+ end
144
+ end
145
+
146
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rjack-slf4j
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.11.0
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-tarpit
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.0
24
+ version:
25
+ description: |-
26
+ A JRuby adaption and gem packaging of the
27
+ {Simple Logging Facade for Java}[http://www.slf4j.org/].
28
+ Provides all jar dependencies and a Ruby Logger compatible
29
+ facade.
30
+
31
+ SLF4J is a java logging abstraction and set of adapters to various
32
+ concrete logging implementations and legacy logging APIs. The slf4j
33
+ gem adds a ruby core Logger compatible facade to SLF4J, and makes any
34
+ needed adapters available to JRuby applications. This makes it
35
+ possible to unify and control logging output of both java and ruby
36
+ components in a JRuby application.
37
+ email:
38
+ - dek-oss@gravitext.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - Manifest.txt
45
+ - README.rdoc
46
+ - History.rdoc
47
+ files:
48
+ - Manifest.static
49
+ - Manifest.txt
50
+ - README.rdoc
51
+ - History.rdoc
52
+ - Rakefile
53
+ - pom.xml
54
+ - assembly.xml
55
+ - lib/rjack-slf4j/base.rb
56
+ - lib/rjack-slf4j.rb
57
+ - lib/rjack-slf4j/jul-to-slf4j.rb
58
+ - lib/rjack-slf4j/jul.rb
59
+ - lib/rjack-slf4j/mdc.rb
60
+ - test/test_slf4j.rb
61
+ - lib/rjack-slf4j/jcl-over-slf4j.rb
62
+ - lib/rjack-slf4j/jcl.rb
63
+ - lib/rjack-slf4j/jdk14.rb
64
+ - lib/rjack-slf4j/log4j-over-slf4j.rb
65
+ - lib/rjack-slf4j/log4j12.rb
66
+ - lib/rjack-slf4j/nop.rb
67
+ - lib/rjack-slf4j/simple.rb
68
+ - lib/rjack-slf4j/jcl-over-slf4j-1.5.11.jar
69
+ - lib/rjack-slf4j/jul-to-slf4j-1.5.11.jar
70
+ - lib/rjack-slf4j/log4j-over-slf4j-1.5.11.jar
71
+ - lib/rjack-slf4j/slf4j-api-1.5.11.jar
72
+ - lib/rjack-slf4j/slf4j-jcl-1.5.11.jar
73
+ - lib/rjack-slf4j/slf4j-jdk14-1.5.11.jar
74
+ - lib/rjack-slf4j/slf4j-log4j12-1.5.11.jar
75
+ - lib/rjack-slf4j/slf4j-nop-1.5.11.jar
76
+ - lib/rjack-slf4j/slf4j-simple-1.5.11.jar
77
+ has_rdoc: true
78
+ homepage: http://rjack.rubyforge.org
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --main
84
+ - README.rdoc
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ requirements: []
100
+
101
+ rubyforge_project: rjack
102
+ rubygems_version: 1.3.5
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: A JRuby adaption and gem packaging of the {Simple Logging Facade for Java}[http://www.slf4j.org/]
106
+ test_files:
107
+ - test/test_slf4j.rb