Skip to content

Commit cfdfc25

Browse files
committed
Merge remote-tracking branch 'upstream/master' into jakarta-update
# Conflicts: # .github/workflows/maven.yml # pom.xml # src/main/java/org/jruby/rack/ext/Logger.java # src/spec/ruby/jruby/rack/integration_spec.rb
2 parents 95243be + 6ffc22f commit cfdfc25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+638
-202
lines changed

.github/workflows/maven.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818

1919
strategy:
2020
matrix:
21-
jruby_version: [ '9.4.13.0', '10.0.1.0' ]
21+
jruby_version: [ '9.4.13.0', '10.0.2.0' ]
2222
java_version: [ '17', '21' ]
2323
exclude:
24-
- jruby_version: '10.0.1.0'
24+
- jruby_version: '10.0.2.0'
2525
java_version: '17' # JRuby 10 requires Java 21
2626
fail-fast: false
2727

@@ -50,13 +50,13 @@ jobs:
5050

5151
strategy:
5252
matrix:
53-
jruby_version: [ '9.4.13.0', '10.0.1.0' ]
53+
jruby_version: [ '9.4.13.0', '10.0.2.0' ]
5454
java_version: [ '17', '21' ]
5555
appraisal: [ 'rails50', 'rails52', 'rails60', 'rails61', 'rails70', 'rails71', 'rails72', 'rails80' ]
5656
exclude:
5757
- jruby_version: '9.4.13.0'
5858
appraisal: 'rails80' # Requires Ruby 3.4 compatibility, which JRuby 9.4 does not support
59-
- jruby_version: '10.0.1.0'
59+
- jruby_version: '10.0.2.0'
6060
java_version: '17' # JRuby 10 requires Java 21
6161
fail-fast: false
6262

@@ -75,7 +75,7 @@ jobs:
7575
cache: maven
7676

7777
- name: Setup JRuby
78-
uses: ruby/setup-ruby@2a7b30092b0caf9c046252510f9273b4875f3db9 # v1.254.0
78+
uses: ruby/setup-ruby@829114fc20da43a41d27359103ec7a63020954d4 # v1.255.0
7979
with:
8080
ruby-version: jruby-${{ matrix.jruby_version }}
8181
bundler-cache: 'false' # Need to install later so we can vary from Gemfile.lock as required for JRuby version compatibility

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@ logging system, configure `jruby.rack.logging` as follows:
297297
- `servlet_context` (default): Sends log messages to the servlet context.
298298
- `stdout`: Sends log messages to the standard output stream `System.out`.
299299
- `slf4j`: Sends log messages to SLF4J. SLF4J configuration is left up to you,
300-
please refer to http://www.slf4j.org/docs.html .
301-
- `log4j`: Sends log messages to log4J. Again, Log4J configuration is
302-
left up to you, consult http://logging.apache.org/log4j/ .
300+
please refer to https://www.slf4j.org/manual.html .
301+
- `log4j`: Sends log messages through Log4j. Only Log4j 2.x is supported, for
302+
- configuration please consult https://logging.apache.org/log4j/2.x/index.html .
303303
- `commons_logging`: Routes logs to commons-logging. You still need to configure
304-
an underlying logging implementation with JCL. We recommend using the logger
305-
library wrapper directly if possible, see http://commons.apache.org/logging/ .
304+
an underlying logging implementation with JCL.
305+
We recommend rather using the logger library wrapper directly when possible.
306306
- `jul`: Directs log messages via Java's core logging facilities (util.logging).
307307

308308
For those loggers that require a specific named logger, set it with the

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ task :speconly => [ :resources, :test_resources ] do
108108
if ENV['SKIP_SPECS'].to_s == 'true'
109109
puts "Skipping specs due to SKIP_SPECS=#{ENV['SKIP_SPECS']}"
110110
else
111-
opts = ENV['SPEC_OPTS'] ? ENV['SPEC_OPTS'] : %q{ --format documentation --color }
111+
opts = ENV['SPEC_OPTS'] ? ENV['SPEC_OPTS'] : %q{ --format documentation --force-color }
112112
spec = ENV['SPEC'] || File.join(Dir.getwd, "src/spec/ruby/**/*_spec.rb")
113113
opts = opts.split(' ').push *FileList[spec].to_a
114114
ruby = ENV['RUBY'] || 'jruby'
@@ -165,7 +165,7 @@ end
165165

166166
desc "Build the jruby-rack-#{GEM_VERSION}.gem"
167167
task :gem => [target_jar, target_jruby_rack, target_jruby_rack_version] do
168-
Rake::Task['spec'].invoke unless ENV['SKIP_SPEC'] == 'true'
168+
Rake::Task['spec'].invoke unless ENV['SKIP_SPECS'] == 'true'
169169
cp FileList["History.md", "LICENSE.txt", "README.md"], "target/gem"
170170
cp target_jar, "target/gem/lib"
171171
if (jars = FileList["target/gem/lib/*.jar"].to_a).size > 1

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<jruby.maven.plugins.version>3.0.6</jruby.maven.plugins.version>
2424
<gem.home>${project.build.directory}/rubygems</gem.home>
2525
<slf4j.version>2.0.17</slf4j.version>
26+
<log4j.version>2.22.1</log4j.version>
2627
<spring.version>6.2.9</spring.version>
2728
</properties>
2829

@@ -117,6 +118,18 @@
117118
<version>${slf4j.version}</version>
118119
<scope>test</scope>
119120
</dependency>
121+
<dependency>
122+
<groupId>org.apache.logging.log4j</groupId>
123+
<artifactId>log4j-api</artifactId>
124+
<version>${log4j.version}</version>
125+
<scope>provided</scope>
126+
</dependency>
127+
<dependency>
128+
<groupId>org.apache.logging.log4j</groupId>
129+
<artifactId>log4j-core</artifactId>
130+
<version>${log4j.version}</version>
131+
<scope>test</scope>
132+
</dependency>
120133
<dependency>
121134
<groupId>org.springframework</groupId>
122135
<artifactId>spring-web</artifactId>

src/main/java/org/jruby/rack/DefaultRackConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ protected RackLogger createLogger(final String loggerClass) {
166166
throw new RackException("could not create logger: '" + loggerClass + "'", e.getTargetException());
167167
}
168168
}
169-
//catch (ClassNotFoundException e) {
170-
// if ( ! isQuiet() ) {
171-
// err.println("failed creating logger: '" + loggerClass + "'");
172-
// e.printStackTrace(err);
173-
// }
174-
//}
175169
catch (Exception e) {
176170
if ( ! isQuiet() ) {
177171
err.println("failed creating logger: '" + loggerClass + "'");
@@ -411,6 +405,7 @@ private static Map<String,String> getLoggerTypes() {
411405
final Map<String,String> loggerTypes = new HashMap<>(8);
412406
loggerTypes.put("commons_logging", "org.jruby.rack.logging.CommonsLoggingLogger");
413407
loggerTypes.put("clogging", "org.jruby.rack.logging.CommonsLoggingLogger");
408+
loggerTypes.put("log4j", "org.jruby.rack.logging.Log4jLogger");
414409
loggerTypes.put("slf4j", "org.jruby.rack.logging.Slf4jLogger");
415410
loggerTypes.put("jul", "org.jruby.rack.logging.JulLogger");
416411
return loggerTypes;

src/main/java/org/jruby/rack/RackContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
* @author nicksieger
1414
*/
1515
public interface RackContext extends RackLogger {
16-
RackConfig getConfig(); /// NOTE: deprecate ?
16+
RackConfig getConfig();
1717
String getServerInfo();
1818
}

src/main/java/org/jruby/rack/RackLogger.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ public void setLevel(Level level) { /* noop */ }
4747
public boolean isFormatting() { return false; }
4848
public void setFormatting(boolean flag) { /* noop */ }
4949
}
50+
51+
interface DelegatingLogger extends RackLogger {
52+
RackLogger unwrapLogger();
53+
}
5054
}

src/main/java/org/jruby/rack/RackServletContextListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public RackServletContextListener() {
3939
this.factory = factory;
4040
}
4141

42+
@Override
4243
public void contextInitialized(final ServletContextEvent event) {
4344
final ServletContext context = event.getServletContext();
4445
final ServletRackConfig config = new ServletRackConfig(context);
@@ -54,6 +55,7 @@ public void contextInitialized(final ServletContextEvent event) {
5455
}
5556
}
5657

58+
@Override
5759
public void contextDestroyed(final ServletContextEvent event) {
5860
final ServletContext context = event.getServletContext();
5961
final RackApplicationFactory factory =

src/main/java/org/jruby/rack/ext/Logger.java

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.jruby.rack.RackContext;
4040
import org.jruby.rack.RackLogger;
4141
import org.jruby.rack.logging.ServletContextLogger;
42-
import org.jruby.rack.util.ExceptionUtils;
4342
import org.jruby.runtime.Block;
4443
import org.jruby.runtime.ObjectAllocator;
4544
import org.jruby.runtime.ThreadContext;
@@ -59,6 +58,8 @@ public class Logger extends RubyObject { // implements RackLogger
5958

6059
// Logger::Severity :
6160

61+
private static final int LEVEL_NOT_SET = -1;
62+
6263
// Low-level information, mostly for developers.
6364
static final int DEBUG = 0;
6465
// Generic (useful) information about system operation.
@@ -72,9 +73,7 @@ public class Logger extends RubyObject { // implements RackLogger
7273
// An unknown message that should always be logged.
7374
static final int UNKNOWN = 5;
7475

75-
private static final int NOT_SET = -1;
76-
77-
private int level = NOT_SET;
76+
private int level = LEVEL_NOT_SET;
7877

7978
private RackLogger logger; // the "real" logger
8079
private IRubyObject formatter = null; // optional
@@ -123,6 +122,10 @@ public IRubyObject initialize_copy(final ThreadContext context, final IRubyObjec
123122

124123
@JRubyMethod
125124
public IRubyObject real_logger(final ThreadContext context) {
125+
RackLogger logger = this.logger;
126+
if (logger instanceof RackLogger.DelegatingLogger) {
127+
logger = ((RackLogger.DelegatingLogger) logger).unwrapLogger();
128+
}
126129
return JavaEmbedUtils.javaToRuby(context.runtime, logger);
127130
}
128131

@@ -132,14 +135,16 @@ public RackLogger getRealLogger() {
132135

133136
@JRubyMethod(name = "level", alias = "sev_threshold")
134137
public IRubyObject get_level(final ThreadContext context) {
135-
if ( this.level == NOT_SET ) return context.nil;
136-
return context.runtime.newFixnum(this.level);
138+
return this.level == LEVEL_NOT_SET ? context.nil : context.runtime.newFixnum(this.level);
137139
}
138140

139141
@JRubyMethod(name = "level=", alias = "sev_threshold=")
140142
public IRubyObject set_level(final ThreadContext context, final IRubyObject level) {
141-
if ( level.isNil() ) { this.level = NOT_SET; return level; }
142-
this.level = (int) level.convertToInteger("to_i").getLongValue();
143+
if ( level.isNil() ) {
144+
this.level = LEVEL_NOT_SET;
145+
return level;
146+
}
147+
this.level = toInt(level);
143148
return get_level(context);
144149
}
145150

@@ -182,10 +187,9 @@ private boolean isEnabledFor(final int severity) {
182187
return isEnabledFor(severity, mapLevel(severity));
183188
}
184189

185-
private boolean isEnabledFor(final int severity,
186-
final RackLogger.Level loggerLevel) {
190+
private boolean isEnabledFor(final int severity, final RackLogger.Level loggerLevel) {
187191
if ( loggerLevel == null ) return level <= severity;
188-
if ( level == NOT_SET ) return logger.isEnabled(loggerLevel);
192+
if ( level == LEVEL_NOT_SET) return logger.isEnabled(loggerLevel);
189193
return level <= severity && logger.isEnabled(loggerLevel);
190194
}
191195

@@ -337,9 +341,7 @@ public IRubyObject unknown(final ThreadContext context, final Block block) {
337341
public IRubyObject add(final ThreadContext context, final IRubyObject[] args, final Block block) {
338342
int severity = UNKNOWN;
339343
final IRubyObject sev = args[0];
340-
if ( ! sev.isNil() ) {
341-
severity = (int) sev.convertToInteger("to_i").getLongValue();
342-
}
344+
if ( !sev.isNil() ) severity = toInt(sev);
343345
IRubyObject msg;
344346
if ( args.length > 1 ) {
345347
msg = args[1];
@@ -358,8 +360,7 @@ public IRubyObject add(final ThreadContext context, final IRubyObject severity,
358360
return context.runtime.newBoolean( add(UNKNOWN, context, msg, block) );
359361
}
360362

361-
private boolean add(final int severity, final ThreadContext context,
362-
IRubyObject msg, final Block block) {
363+
private boolean add(final int severity, final ThreadContext context, IRubyObject msg, final Block block) {
363364
// severity ||= UNKNOWN
364365
final RackLogger.Level loggerLevel = mapLevel(severity);
365366

@@ -380,9 +381,8 @@ private boolean add(final int severity, final ThreadContext context,
380381
final long datetime = System.currentTimeMillis();
381382
msg = format_message(context, severity, datetime, progname, msg);
382383
}
383-
else if (msg instanceof RubyException error) { // print backtrace for error
384-
error.prepareIntegratedBacktrace(context, null);
385-
doLog( loggerLevel, ExceptionUtils.formatError(error) );
384+
else if ( msg instanceof RubyException ex ) {
385+
doLog( loggerLevel, ex.toThrowable() );
386386
return true;
387387
}
388388
// @logdev.write(format_message(format_severity(severity), Time.now, progname, message))
@@ -414,16 +414,14 @@ public IRubyObject format_message(final ThreadContext context, final IRubyObject
414414
private IRubyObject format_message(final ThreadContext context,
415415
final int severityVal, final long datetimeMillis,
416416
final IRubyObject progname, final IRubyObject msg) {
417-
final IRubyObject severity =
418-
RubyString.newStringShared(context.runtime, formatSeverity(severityVal));
417+
final IRubyObject severity = RubyString.newStringShared(context.runtime, formatSeverity(severityVal));
419418
final RubyTime datetime = RubyTime.newTime(context.runtime, datetimeMillis);
420419
return format_message(context, new IRubyObject[] { severity, datetime, progname, msg });
421420
}
422421

423422
@JRubyMethod(visibility = Visibility.PRIVATE)
424423
public IRubyObject format_severity(final ThreadContext context, final IRubyObject sev) {
425-
final int severity = (int) sev.convertToInteger("to_i").getLongValue();
426-
return RubyString.newStringShared(context.runtime, formatSeverity(severity));
424+
return RubyString.newStringShared(context.runtime, formatSeverity(toInt(sev)));
427425
}
428426

429427
private static final ByteList FORMATTED_DEBUG =
@@ -450,27 +448,27 @@ private static ByteList formatSeverity(final int severity) {
450448
};
451449
}
452450

451+
private static int toInt(final IRubyObject level) {
452+
return level.convertToInteger("to_i").getIntValue();
453+
}
454+
453455
@SuppressWarnings("unchecked")
454456
@Override
455457
public <T> T toJava(Class<T> target) {
456-
// NOTE: maybe this is not a good idea ?!
457-
if ( RackLogger.class == target ) return (T) logger;
458+
if ( RackLogger.class.isAssignableFrom(target) && target.isInstance(logger) ) return (T) logger;
458459
return super.toJava(target);
459460
}
460461

461-
private void doLog(RackLogger.Level level, CharSequence message) {
462-
logger.log( level, message );
462+
private void doLog(RackLogger.Level level, Throwable ex) {
463+
logger.log(level, "", ex);
463464
}
464465

465-
private void doLog(RubyString message) {
466-
logger.log( message );
466+
private void doLog(RackLogger.Level level, CharSequence message) {
467+
logger.log(level, message);
467468
}
468469

469-
// (old) BufferedLogger API compatibility :
470-
471-
@JRubyMethod(name = "flush", alias = { "auto_flushing", "auto_flushing=" })
472-
public IRubyObject stub(final ThreadContext context) {
473-
return context.nil;
470+
private void doLog(RubyString message) {
471+
logger.log(message);
474472
}
475473

476474
/**

0 commit comments

Comments
 (0)