@@ -312,7 +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- // NOTE possible to "somehow" support UNKNOWN in RackLogger ?!
315+ // NOTE possibly - "somehow" support UNKNOWN in RackLogger ?!
316316 return context .runtime .newBoolean ( add (UNKNOWN , context , msg , block ) );
317317 }
318318
@@ -341,9 +341,7 @@ public IRubyObject add(final ThreadContext context,
341341 public IRubyObject add (final ThreadContext context ,
342342 final IRubyObject severity , final IRubyObject msg ,
343343 final IRubyObject progname , final Block block ) {
344-
345- // TODO support UNKNOWN in RackLogger ?!
346-
344+ // NOTE possibly - "somehow" support UNKNOWN in RackLogger ?!
347345 return context .runtime .newBoolean ( add (UNKNOWN , context , msg , block ) );
348346 }
349347
@@ -445,20 +443,21 @@ private static ByteList formatSeverity(final int severity) {
445443
446444 /*
447445 private static String formatSeverity(final int severity) {
448- switch ( severity) {
449- case DEBUG: return "DEBUG";
450- case INFO : return "INFO" ;
451- case WARN : return "WARN" ;
452- case ERROR: return "ERROR";
453- case FATAL: return "FATAL";
454- }
455- return "ANY";
446+ switch ( severity) {
447+ case DEBUG: return "DEBUG";
448+ case INFO : return "INFO" ;
449+ case WARN : return "WARN" ;
450+ case ERROR: return "ERROR";
451+ case FATAL: return "FATAL";
452+ }
453+ return "ANY";
456454 } */
457455
458456 // RackLogger
459457
460458 @ Override
461459 public Object toJava (Class target ) {
460+ // NOTE: maybe this is not a good idea ?!
462461 if ( RackLogger .class == target ) return logger ;
463462 return super .toJava (target );
464463 }
@@ -498,17 +497,63 @@ public void log(Level level, String message, Throwable ex) {
498497
499498 @Override @Deprecated
500499 public void log(String level, String message) {
501- logger.log(Level.valueOf( level) , message);
500+ logger.log(level, message);
502501 }
503502
504503 @Override @Deprecated
505504 public void log(String level, String message, Throwable ex) {
506- logger.log(Level.valueOf( level) , message, ex);
505+ logger.log(level, message, ex);
507506 } */
508507
508+ // LoggerSilence API :
509+
510+ private static boolean silencer = false ; // we're NOT true by default!
511+
512+ @ JRubyMethod (name = "silencer" , meta = true )
513+ public static IRubyObject get_silencer (final ThreadContext context , final IRubyObject self ) {
514+ return context .runtime .newBoolean (silencer );
515+ }
516+
517+ @ JRubyMethod (name = "silencer=" , meta = true )
518+ public static IRubyObject set_silencer (final ThreadContext context , final IRubyObject self ,
519+ final IRubyObject value ) {
520+ return context .runtime .newBoolean (silencer = value .isTrue ());
521+ }
522+
523+ @ JRubyMethod (name = "silence" )
524+ public IRubyObject silence (final ThreadContext context , final Block block ) {
525+ return doSilence (ERROR , context , block ); // temp_level = Logger::ERROR
526+ }
527+
528+ @ JRubyMethod (name = "silence" , required = 1 )
529+ public IRubyObject silence (final ThreadContext context ,
530+ final IRubyObject temp_level , final Block block ) {
531+ final int tempLevel = (int ) temp_level .convertToInteger ("to_i" ).getLongValue ();
532+ return doSilence (tempLevel , context , block );
533+ }
534+
535+ private IRubyObject doSilence (final int tempLevel ,
536+ final ThreadContext context , final Block block ) {
537+ if ( silencer ) {
538+ try { // not implemented - on purpose!
539+ return block .yield (context , this );
540+ }
541+ finally { /* noop */ }
542+ }
543+ else {
544+ return block .yield (context , this );
545+ }
546+ }
547+
548+ // (old) BufferedLogger API compatibility :
549+
550+ @ JRubyMethod (name = "flush" , alias = { "auto_flushing" , "auto_flushing=" })
551+ public IRubyObject stub (final ThreadContext context ) {
552+ return context .nil ;
553+ }
509554
510555 /**
511- * @deprecated Likely not used at all, mostly for 1.1 compatibility!
556+ * @deprecated Likely, no longer used at all, mostly for 1.1 compatibility.
512557 */
513558 @ JRubyClass (name ="JRuby::Rack::ServletLog" )
514559 public static class ServletLog extends RubyObject {
@@ -564,19 +609,17 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
564609
565610 @ JRubyMethod
566611 public IRubyObject write (final IRubyObject msg ) {
567- // NOTE: this is a Java RackContext#log (RackLogger#log) call ...
568- //return getInstanceVariable("@context").callMethod(context, "log", msg);
569612 context .log ( msg .toString () );
570613 return msg ;
571614 }
572615
573616 @ JRubyMethod
574617 public IRubyObject puts (final IRubyObject msg ) {
575- return write (msg ); // return this.callMethod(context, "write", msg);
618+ return write (msg );
576619 }
577620
578621 @ JRubyMethod (name = "close" , alias = "flush" )
579- public IRubyObject close (final ThreadContext context ) {
622+ public IRubyObject noop (final ThreadContext context ) {
580623 return context .nil ; /* NOOP */
581624 }
582625
0 commit comments