Skip to content

Commit 5513066

Browse files
committed
setup JRuby::Rack.logger.class' level constants (for better ::Logger compatibility)
1 parent e6c83b8 commit 5513066

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ public IRubyObject fatal(final ThreadContext context,
312312
@JRubyMethod(name = "unknown")
313313
public IRubyObject unknown(final ThreadContext context,
314314
final IRubyObject msg, final Block block) {
315-
316-
// TODO support UNKNOWN in RackLogger ?!
317-
315+
// NOTE possible to "somehow" support UNKNOWN in RackLogger ?!
318316
return context.runtime.newBoolean( add(UNKNOWN, context, msg, block) );
319317
}
320318

@@ -510,7 +508,7 @@ public void log(String level, String message, Throwable ex) {
510508

511509

512510
/**
513-
* @deprecated mostly for 1.1 compatibility
511+
* @deprecated Likely not used at all, mostly for 1.1 compatibility!
514512
*/
515513
@JRubyClass(name="JRuby::Rack::ServletLog")
516514
public static class ServletLog extends RubyObject {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ public static void load(final Ruby runtime) {
6161
"Logger", _Object, Logger.ALLOCATOR
6262
);
6363
_Logger.defineAnnotatedMethods(Logger.class);
64+
// Rails compatibility as it assumes logger.class::DEBUG to work :
65+
_Logger.setConstant("DEBUG", runtime.newFixnum(Logger.DEBUG));
66+
_Logger.setConstant("INFO", runtime.newFixnum(Logger.INFO));
67+
_Logger.setConstant("WARN", runtime.newFixnum(Logger.WARN));
68+
_Logger.setConstant("ERROR", runtime.newFixnum(Logger.ERROR));
69+
_Logger.setConstant("FATAL", runtime.newFixnum(Logger.FATAL));
70+
//_Logger.setConstant("UNKNOWN", runtime.newFixnum(Logger.UNKNOWN));
6471
// JRuby::Rack::ServletLog
6572
final RubyClass _ServletLog = _JRuby_Rack.defineClassUnder(
6673
"ServletLog", _Object, Logger.ServletLog.ALLOCATOR

src/spec/ruby/jruby/rack/logger_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@
9696
expect( real_logger.formatting? ).to be false
9797
end
9898

99-
# it 'handles constant resolution (for Rails compatibility)' do
100-
# expect( logger.class::DEBUG ).to eql 0
101-
# expect( logger.class::FATAL ).to eql 4
102-
# end
99+
it 'handles constant resolution (for Rails compatibility)' do
100+
expect( logger.class::DEBUG ).to eql 0
101+
expect( logger.class::FATAL ).to eql 4
102+
end
103103

104104
describe JRuby::Rack::ServletLog do
105105

0 commit comments

Comments
 (0)