edu.rice.cs.plt.debug
Class FilteredLogSink

java.lang.Object
  extended by edu.rice.cs.plt.debug.FilteredLogSink
All Implemented Interfaces:
LogSink, java.io.Closeable

public class FilteredLogSink
extends java.lang.Object
implements LogSink

A LogSink that discards any messages that are not accepted by a given predicate. Messages that match are passed on to another LogSink. For convenience, a variety of Message predicate constructors are defined in the class; these can be composed with the methods in LambdaUtil.

See Also:
LambdaUtil.and(Predicate, Predicate), LambdaUtil.or(Predicate, Predicate), LambdaUtil.negate(Predicate)

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.rice.cs.plt.debug.LogSink
LogSink.EndMessage, LogSink.ErrorMessage, LogSink.Message, LogSink.MessageVisitor<T>, LogSink.StackMessage, LogSink.StandardMessage, LogSink.StartMessage, LogSink.ValueMessage
 
Constructor Summary
FilteredLogSink(LogSink delegate, Predicate<? super LogSink.Message> pred)
           
 
Method Summary
static FilteredLogSink byLocation(LogSink delegate, Predicate<? super java.lang.String> pred)
          Create a LogSink filtered by a locationPredicate(edu.rice.cs.plt.lambda.Predicate).
static FilteredLogSink byLocationBlackList(LogSink delegate, java.lang.String... prefixes)
          Create a LogSink filtered by a locationBlackListPredicate(java.lang.String...).
static FilteredLogSink byLocationWhiteList(LogSink delegate, java.lang.String... prefixes)
          Create a LogSink filtered by a locationWhiteListPredicate(java.lang.String...).
static FilteredLogSink byStackDepth(LogSink delegate, int maxDepth)
          Create a LogSink filtered by a stackDepthPredicate(int).
static FilteredLogSink byThread(LogSink delegate, Predicate<? super ThreadSnapshot> pred)
          Create a LogSink filtered by a threadPredicate(edu.rice.cs.plt.lambda.Predicate).
static FilteredLogSink byThreadBlackList(LogSink delegate, java.lang.String... nameParts)
          Create a LogSink filtered by a threadBlackListPredicate(java.lang.Thread...).
static FilteredLogSink byThreadBlackList(LogSink delegate, java.lang.Thread... threads)
          Create a LogSink filtered by a threadBlackListPredicate(java.lang.Thread...).
static FilteredLogSink byThreadWhiteList(LogSink delegate, java.lang.String... nameParts)
          Create a LogSink filtered by a threadWhiteListPredicate(java.lang.Thread...).
static FilteredLogSink byThreadWhiteList(LogSink delegate, java.lang.Thread... threads)
          Create a LogSink filtered by a threadWhiteListPredicate(java.lang.Thread...).
 void close()
           
static Predicate<LogSink.Message> locationBlackListPredicate(java.lang.String... prefixes)
          Produce a predicate that rejects any caller locations starting with the given prefixes.
static Predicate<LogSink.Message> locationPredicate(Predicate<? super java.lang.String> pred)
          Produce a predicate that accepts messages iff their caller location is accepted by pred.
static Predicate<LogSink.Message> locationWhiteListPredicate(java.lang.String... prefixes)
          Produce a predicate that accepts only caller locations starting with the given prefixes.
 void log(LogSink.StandardMessage m)
           
 void logEnd(LogSink.EndMessage m)
           
 void logError(LogSink.ErrorMessage m)
           
 void logStack(LogSink.StackMessage m)
           
 void logStart(LogSink.StartMessage m)
           
static Predicate<LogSink.Message> stackDepthPredicate(int maxDepth)
          Produce a predicate that only accepts message with stack traces of at most the given depth.
static Predicate<LogSink.Message> threadBlackListPredicate(java.lang.String... nameParts)
          Produce a predicate that only accepts messages logged from threads matching the given names.
static Predicate<LogSink.Message> threadBlackListPredicate(java.lang.Thread... threads)
          Produce a predicate that only accepts messages logged from the given thread.
static Predicate<LogSink.Message> threadPredicate(Predicate<? super ThreadSnapshot> pred)
          Produce a predicate that accepts messages iff their associated ThreadSnapshot is accepted by pred.
static Predicate<LogSink.Message> threadWhiteListPredicate(java.lang.String... nameParts)
          Produce a predicate that only accepts messages logged from threads matching the given names.
static Predicate<LogSink.Message> threadWhiteListPredicate(java.lang.Thread... threads)
          Produce a predicate that only accepts messages logged from the given thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteredLogSink

public FilteredLogSink(LogSink delegate,
                       Predicate<? super LogSink.Message> pred)
Method Detail

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException

log

public void log(LogSink.StandardMessage m)
Specified by:
log in interface LogSink

logEnd

public void logEnd(LogSink.EndMessage m)
Specified by:
logEnd in interface LogSink

logError

public void logError(LogSink.ErrorMessage m)
Specified by:
logError in interface LogSink

logStack

public void logStack(LogSink.StackMessage m)
Specified by:
logStack in interface LogSink

logStart

public void logStart(LogSink.StartMessage m)
Specified by:
logStart in interface LogSink

byLocationWhiteList

public static FilteredLogSink byLocationWhiteList(LogSink delegate,
                                                  java.lang.String... prefixes)
Create a LogSink filtered by a locationWhiteListPredicate(java.lang.String...).


byLocationBlackList

public static FilteredLogSink byLocationBlackList(LogSink delegate,
                                                  java.lang.String... prefixes)
Create a LogSink filtered by a locationBlackListPredicate(java.lang.String...).


byLocation

public static FilteredLogSink byLocation(LogSink delegate,
                                         Predicate<? super java.lang.String> pred)
Create a LogSink filtered by a locationPredicate(edu.rice.cs.plt.lambda.Predicate).


byStackDepth

public static FilteredLogSink byStackDepth(LogSink delegate,
                                           int maxDepth)
Create a LogSink filtered by a stackDepthPredicate(int).


byThreadWhiteList

public static FilteredLogSink byThreadWhiteList(LogSink delegate,
                                                java.lang.Thread... threads)
Create a LogSink filtered by a threadWhiteListPredicate(java.lang.Thread...).


byThreadWhiteList

public static FilteredLogSink byThreadWhiteList(LogSink delegate,
                                                java.lang.String... nameParts)
Create a LogSink filtered by a threadWhiteListPredicate(java.lang.Thread...).


byThreadBlackList

public static FilteredLogSink byThreadBlackList(LogSink delegate,
                                                java.lang.Thread... threads)
Create a LogSink filtered by a threadBlackListPredicate(java.lang.Thread...).


byThreadBlackList

public static FilteredLogSink byThreadBlackList(LogSink delegate,
                                                java.lang.String... nameParts)
Create a LogSink filtered by a threadBlackListPredicate(java.lang.Thread...).


byThread

public static FilteredLogSink byThread(LogSink delegate,
                                       Predicate<? super ThreadSnapshot> pred)
Create a LogSink filtered by a threadPredicate(edu.rice.cs.plt.lambda.Predicate).


locationWhiteListPredicate

public static Predicate<LogSink.Message> locationWhiteListPredicate(java.lang.String... prefixes)
Produce a predicate that accepts only caller locations starting with the given prefixes. A prefix p matches a caller location loc iff (loc.getClassName() + "." + loc.getMethodName()).startsWith(p). If no caller information is available, the empty string is used.


locationBlackListPredicate

public static Predicate<LogSink.Message> locationBlackListPredicate(java.lang.String... prefixes)
Produce a predicate that rejects any caller locations starting with the given prefixes. A prefix p matches a caller location loc iff (loc.getClassName() + "." + loc.getMethodName()).startsWith(p). If no caller information is available, the empty string is used.


locationPredicate

public static Predicate<LogSink.Message> locationPredicate(Predicate<? super java.lang.String> pred)
Produce a predicate that accepts messages iff their caller location is accepted by pred. The caller location string is defined for a location loc as loc.getClassName() + "." + loc.getMethodName(). If no caller information is available, the empty string is used.


stackDepthPredicate

public static Predicate<LogSink.Message> stackDepthPredicate(int maxDepth)
Produce a predicate that only accepts message with stack traces of at most the given depth.


threadWhiteListPredicate

public static Predicate<LogSink.Message> threadWhiteListPredicate(java.lang.Thread... threads)
Produce a predicate that only accepts messages logged from the given thread.


threadWhiteListPredicate

public static Predicate<LogSink.Message> threadWhiteListPredicate(java.lang.String... nameParts)
Produce a predicate that only accepts messages logged from threads matching the given names. A thread matches a name part s iff its name contains s.


threadBlackListPredicate

public static Predicate<LogSink.Message> threadBlackListPredicate(java.lang.Thread... threads)
Produce a predicate that only accepts messages logged from the given thread.


threadBlackListPredicate

public static Predicate<LogSink.Message> threadBlackListPredicate(java.lang.String... nameParts)
Produce a predicate that only accepts messages logged from threads matching the given names. A thread matches a name part s iff its name contains s.


threadPredicate

public static Predicate<LogSink.Message> threadPredicate(Predicate<? super ThreadSnapshot> pred)
Produce a predicate that accepts messages iff their associated ThreadSnapshot is accepted by pred.