@@ -109,11 +109,8 @@ private void initialize(final IRubyObject context) {
109
109
if ( context instanceof RackLogger ) {
110
110
this .logger = (RackLogger ) context ;
111
111
}
112
- else if ( context instanceof RackContext ) {
113
- this .logger = ((RackContext ) context ).getConfig ().getLogger ();
114
- }
115
112
else {
116
- this .logger = ( RackLogger ) context .toJava (RackLogger .class );
113
+ this .logger = context .toJava (RackLogger .class );
117
114
}
118
115
}
119
116
@@ -285,8 +282,7 @@ public IRubyObject debug(final ThreadContext context,
285
282
// See #add.
286
283
//
287
284
@ JRubyMethod (name = "info" )
288
- public IRubyObject info (final ThreadContext context ,
289
- final IRubyObject msg , final Block block ) {
285
+ public IRubyObject info (final ThreadContext context , final IRubyObject msg , final Block block ) {
290
286
return context .runtime .newBoolean ( add (INFO , context , msg , block ) );
291
287
}
292
288
@@ -299,8 +295,7 @@ public IRubyObject info(final ThreadContext context, final Block block) {
299
295
// Log a +WARN+ message.
300
296
//
301
297
@ JRubyMethod (name = "warn" )
302
- public IRubyObject warn (final ThreadContext context ,
303
- final IRubyObject msg , final Block block ) {
298
+ public IRubyObject warn (final ThreadContext context , final IRubyObject msg , final Block block ) {
304
299
return context .runtime .newBoolean ( add (WARN , context , msg , block ) );
305
300
}
306
301
@@ -313,8 +308,7 @@ public IRubyObject warn(final ThreadContext context, final Block block) {
313
308
// Log a +ERROR+ message.
314
309
//
315
310
@ JRubyMethod (name = "error" )
316
- public IRubyObject error (final ThreadContext context ,
317
- final IRubyObject msg , final Block block ) {
311
+ public IRubyObject error (final ThreadContext context , final IRubyObject msg , final Block block ) {
318
312
return context .runtime .newBoolean ( add (ERROR , context , msg , block ) );
319
313
}
320
314
@@ -327,8 +321,7 @@ public IRubyObject error(final ThreadContext context, final Block block) {
327
321
// Log a +FATAL+ message.
328
322
//
329
323
@ JRubyMethod (name = "fatal" )
330
- public IRubyObject fatal (final ThreadContext context ,
331
- final IRubyObject msg , final Block block ) {
324
+ public IRubyObject fatal (final ThreadContext context , final IRubyObject msg , final Block block ) {
332
325
return context .runtime .newBoolean ( add (FATAL , context , msg , block ) );
333
326
}
334
327
@@ -342,9 +335,7 @@ public IRubyObject fatal(final ThreadContext context, final Block block) {
342
335
// This will be printed no matter what the logger's level is.
343
336
//
344
337
@ JRubyMethod (name = "unknown" )
345
- public IRubyObject unknown (final ThreadContext context ,
346
- final IRubyObject msg , final Block block ) {
347
- // NOTE possibly - "somehow" support UNKNOWN in RackLogger ?!
338
+ public IRubyObject unknown (final ThreadContext context , final IRubyObject msg , final Block block ) {
348
339
return context .runtime .newBoolean ( add (UNKNOWN , context , msg , block ) );
349
340
}
350
341
@@ -375,10 +366,8 @@ public IRubyObject add(final ThreadContext context,
375
366
376
367
// def add(severity, message = nil, progname = nil, &block)
377
368
@ JRubyMethod (name = "add" )
378
- public IRubyObject add (final ThreadContext context ,
379
- final IRubyObject severity , final IRubyObject msg ,
380
- final IRubyObject progname , final Block block ) {
381
- // NOTE possibly - "somehow" support UNKNOWN in RackLogger ?!
369
+ public IRubyObject add (final ThreadContext context , final IRubyObject severity ,
370
+ final IRubyObject msg , final IRubyObject progname , final Block block ) {
382
371
return context .runtime .newBoolean ( add (UNKNOWN , context , msg , block ) );
383
372
}
384
373
@@ -431,17 +420,16 @@ public IRubyObject append(final ThreadContext context, final IRubyObject msg) {
431
420
// private
432
421
433
422
@ JRubyMethod (visibility = Visibility .PRIVATE , required = 4 )
434
- public IRubyObject format_message (final ThreadContext context ,
435
- final IRubyObject [] args ) {
423
+ public IRubyObject format_message (final ThreadContext context , final IRubyObject [] args ) {
436
424
if ( formatter instanceof RubyProc ) {
437
425
return ((RubyProc ) formatter ).call (context , args );
438
426
}
439
427
return formatter .callMethod (context , "call" , args );
440
428
}
441
429
442
430
private IRubyObject format_message (final ThreadContext context ,
443
- final int severityVal , final long datetimeMillis ,
444
- final IRubyObject progname , final IRubyObject msg ) {
431
+ final int severityVal , final long datetimeMillis ,
432
+ final IRubyObject progname , final IRubyObject msg ) {
445
433
final IRubyObject severity =
446
434
RubyString .newStringShared (context .runtime , formatSeverity (severityVal ));
447
435
final RubyTime datetime = RubyTime .newTime (context .runtime , datetimeMillis );
@@ -493,9 +481,9 @@ private static String formatSeverity(final int severity) {
493
481
// RackLogger
494
482
495
483
@ Override
496
- public Object toJava (Class target ) {
484
+ public < T > T toJava (Class < T > target ) {
497
485
// NOTE: maybe this is not a good idea ?!
498
- if ( RackLogger .class == target ) return logger ;
486
+ if ( RackLogger .class == target ) return ( T ) logger ;
499
487
return super .toJava (target );
500
488
}
501
489
@@ -563,14 +551,12 @@ public IRubyObject silence(final ThreadContext context, final Block block) {
563
551
}
564
552
565
553
@ JRubyMethod (name = "silence" , required = 1 )
566
- public IRubyObject silence (final ThreadContext context ,
567
- final IRubyObject temp_level , final Block block ) {
554
+ public IRubyObject silence (final ThreadContext context , final IRubyObject temp_level , final Block block ) {
568
555
final int tempLevel = (int ) temp_level .convertToInteger ("to_i" ).getLongValue ();
569
556
return doSilence (tempLevel , context , block );
570
557
}
571
558
572
- private IRubyObject doSilence (final int tempLevel ,
573
- final ThreadContext context , final Block block ) {
559
+ private IRubyObject doSilence (final int tempLevel , final ThreadContext context , final Block block ) {
574
560
if ( silencer ) {
575
561
try { // not implemented - on purpose!
576
562
return block .yield (context , this );
@@ -607,7 +593,7 @@ protected ServletLog(Ruby runtime, RubyClass metaClass) {
607
593
super (runtime , metaClass );
608
594
}
609
595
610
- @ JRubyMethod (required = 0 , optional = 1 )
596
+ @ JRubyMethod (optional = 1 )
611
597
public IRubyObject initialize (final ThreadContext context , final IRubyObject [] args ) {
612
598
final IRubyObject rackContext ;
613
599
if ( args != null && args .length > 0 ) rackContext = args [0 ];
@@ -623,8 +609,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
623
609
}
624
610
else {
625
611
try {
626
- RackLogger logger = (RackLogger ) rackContext .toJava (RackLogger .class );
627
- this .context = logger ;
612
+ this .context = rackContext .toJava (RackLogger .class );
628
613
}
629
614
catch (RaiseException e ) { // TypeError
630
615
final IRubyObject error = e .getException ();
@@ -633,7 +618,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
633
618
}
634
619
// support passing in a ServletContext instance (for convenience) :
635
620
try {
636
- ServletContext servletContext = ( ServletContext ) rackContext .toJava (ServletContext .class );
621
+ ServletContext servletContext = rackContext .toJava (ServletContext .class );
637
622
this .context = new ServletContextLogger (servletContext );
638
623
}
639
624
catch (RaiseException fail ) {
0 commit comments