log4jruby 3.0.0.rc1-java → 3.0.0.rc2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/lib/log4jruby/logger.rb +13 -1
- data/lib/log4jruby/support/formatter.rb +15 -0
- data/lib/log4jruby/support/jruby_version.rb +15 -0
- data/lib/log4jruby/support/legacy_shim_formatter.rb +34 -0
- data/lib/log4jruby/support/log4j_args.rb +6 -1
- data/lib/log4jruby/support/log_manager.rb +1 -1
- data/lib/log4jruby/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1668efce6b23c33b459992956795614d50f3178ed3c2787e7651f1715b60235
|
4
|
+
data.tar.gz: ba8e28cc7b8dbc9531ccec0cb34b7642ab8beacc37eee8be0cd7df2abb5f661e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c6cbd7bae1b08f33156a3ef73b3e93f00a174bc0e32b2949b5cfff6424a81c3ac12a766a889f618f308fc55fd4f942b3778f4129b3739c4140a4170c4e23a4
|
7
|
+
data.tar.gz: 1763996d46b5e5836c911c6061068245464a952c59ba94f890549ea56bf19b97b322a1112471ecb00e21bffc410c78b0e34e2073c0cbbec2ba53ec629ade2310
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -151,6 +151,10 @@ The default Log4jruby formatter outputs `progname` and `msg` only (as opposed to
|
|
151
151
|
Severity, timestamp, and backtraces are handed according to your `Log4j` configuration.
|
152
152
|
E.g. [PatternLayout](https://logging.apache.org/log4j/2.x/manual/layouts.html).
|
153
153
|
|
154
|
+
* For JRuby versions < 9.3, Ruby exceptions are not passed directly to the `Throwable` arg of log4j. Instead,
|
155
|
+
backtraces are included in the log message by the default formatter. This means that `%throwable` in
|
156
|
+
the log4j config will not affect ruby exceptions for Jruby < 9.3.
|
157
|
+
|
154
158
|
The output of the `formatter` is passed as the `message` parameter of the [Log4j log methods](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#log(org.apache.log4j.Priority,%20java.lang.Object).
|
155
159
|
|
156
160
|
## Development
|
data/lib/log4jruby/logger.rb
CHANGED
@@ -4,6 +4,10 @@ require 'log4jruby/support/log4j_args'
|
|
4
4
|
require 'log4jruby/support/levels'
|
5
5
|
require 'log4jruby/support/location'
|
6
6
|
require 'log4jruby/support/log_manager'
|
7
|
+
require 'log4jruby/support/formatter'
|
8
|
+
require 'log4jruby/support/legacy_shim_formatter'
|
9
|
+
require 'log4jruby/support/jruby_version'
|
10
|
+
|
7
11
|
require 'logger'
|
8
12
|
|
9
13
|
module Log4jruby
|
@@ -121,7 +125,7 @@ module Log4jruby
|
|
121
125
|
return @formatter if defined?(@formatter)
|
122
126
|
|
123
127
|
@formatter = if self == Logger.root
|
124
|
-
|
128
|
+
new_default_formatter
|
125
129
|
else
|
126
130
|
parent.formatter
|
127
131
|
end
|
@@ -167,5 +171,13 @@ module Log4jruby
|
|
167
171
|
@log4j_logger.send(level, msg, throwable)
|
168
172
|
end
|
169
173
|
end
|
174
|
+
|
175
|
+
def new_default_formatter
|
176
|
+
if Support::JrubyVersion.native_ruby_stacktraces_supported?
|
177
|
+
Support::Formatter.new
|
178
|
+
else
|
179
|
+
Support::LegacyShimFormatter.new
|
180
|
+
end
|
181
|
+
end
|
170
182
|
end
|
171
183
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Log4jruby
|
4
|
+
module Support
|
5
|
+
# Default ruby Logger formatter
|
6
|
+
# This formatter mimics
|
7
|
+
# [Logger::Formatter](https://ruby-doc.org/stdlib-2.6.4/libdoc/logger/rdoc/Logger/Formatter.html)
|
8
|
+
# but excludes log level and timestamp to leave it for the Log4j config
|
9
|
+
class Formatter
|
10
|
+
def call(_severity, _time, progname, msg)
|
11
|
+
"-- #{progname}: #{msg}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Log4jruby
|
4
|
+
module Support
|
5
|
+
# Class for explicitly marking JRuby version specific code.
|
6
|
+
# Find consumers and remove this and references when no longer needed.
|
7
|
+
class JrubyVersion
|
8
|
+
class << self
|
9
|
+
def native_ruby_stacktraces_supported?
|
10
|
+
Gem::Version.new(JRUBY_VERSION) >= Gem::Version.new('9.3')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Log4jruby
|
4
|
+
module Support
|
5
|
+
# Default ruby Logger formatter for Jruby < 9.3.x
|
6
|
+
# This formatter mimics
|
7
|
+
# [Logger::Formatter](https://ruby-doc.org/stdlib-2.6.4/libdoc/logger/rdoc/Logger/Formatter.html)
|
8
|
+
# but excludes log level and timestamp (delegated to Log4j).
|
9
|
+
# It also appends full backtraces with nested causes.
|
10
|
+
class LegacyShimFormatter
|
11
|
+
def call(_severity, _time, progname, msg)
|
12
|
+
"-- #{msg2str(progname)}: #{msg2str(msg)}"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def msg2str(msg)
|
18
|
+
case msg
|
19
|
+
when ::String
|
20
|
+
msg
|
21
|
+
when ::Exception
|
22
|
+
exception2str(msg)
|
23
|
+
else
|
24
|
+
msg.inspect
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def exception2str(exception)
|
29
|
+
"#{exception.message} (#{exception.class})\n\t#{exception.backtrace&.join("\n\t")}" \
|
30
|
+
"#{"\nCaused by: #{exception2str(exception.cause)}" if exception.cause}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'log4jruby/support/jruby_version'
|
4
|
+
|
3
5
|
module Log4jruby
|
4
6
|
module Support
|
5
7
|
# Translate logger args for use by Ruby Logger formatter and log4j.
|
@@ -37,7 +39,10 @@ module Log4jruby
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def exception(obj)
|
40
|
-
|
42
|
+
if (JrubyVersion.native_ruby_stacktraces_supported? && obj.is_a?(::Exception)) ||
|
43
|
+
obj.is_a?(Java::java.lang.Throwable)
|
44
|
+
obj
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
data/lib/log4jruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log4jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc2
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Lenny Marks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby Logger using Log4j, geared toward those who use JRuby to write Ruby
|
14
14
|
code using/extending Java code. Ruby and Java are configured together using traditional
|
@@ -24,6 +24,9 @@ files:
|
|
24
24
|
- lib/log4jruby.rb
|
25
25
|
- lib/log4jruby/logger.rb
|
26
26
|
- lib/log4jruby/logger_for_class.rb
|
27
|
+
- lib/log4jruby/support/formatter.rb
|
28
|
+
- lib/log4jruby/support/jruby_version.rb
|
29
|
+
- lib/log4jruby/support/legacy_shim_formatter.rb
|
27
30
|
- lib/log4jruby/support/levels.rb
|
28
31
|
- lib/log4jruby/support/location.rb
|
29
32
|
- lib/log4jruby/support/log4j_args.rb
|
@@ -40,9 +43,9 @@ require_paths:
|
|
40
43
|
- lib
|
41
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
45
|
requirements:
|
43
|
-
- - "
|
46
|
+
- - ">="
|
44
47
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.
|
48
|
+
version: 2.3.3
|
46
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
50
|
requirements:
|
48
51
|
- - ">"
|