com.atlassian.jira.util.log
Class NShotLogger

java.lang.Object
  extended by com.atlassian.jira.util.log.NShotLogger
Direct Known Subclasses:
OneShotLogger

public class NShotLogger
extends Object

An Log4J logger wrapper than will only log N times. After maxTimes number of calls the logger silently discards the logging output.

The logging is done via a delegate Logger

You might use it a bit like this

 private static final Logger log = Logger.getLogger(MyObject.class);
 private final Logger oneShotParseErrorLog = new NShotLogger(log,1);
 ...
 ...
 if (parseErrorOnSomethingThatWeOnlywanToReportOnce == true) {
      oneShotParseErrorLog.log("Things seem quite screwy in your config");
 }
 
Note that the logger is not static. If the object in question is a PICO managed singleton then you will want to use a non static so that the logger will log again if the PICO world is torn down and brought back up again.

Since:
v3.13

Constructor Summary
NShotLogger(org.apache.log4j.Logger delegateLogger, int maxTimes)
          Creates a NShotLogger that will only output log data if it has been called maxTimes or less.
 
Method Summary
 void debug(Object o)
           
 void debug(Object o, Throwable throwable)
           
 void error(Object o)
           
 void error(Object o, Throwable throwable)
           
 void fatal(Object o)
           
 void fatal(Object o, Throwable throwable)
           
 org.apache.log4j.Logger getDelegateLogger()
           
 void info(Object o)
           
 void info(Object o, Throwable throwable)
           
 boolean isDebugEnabled()
           
 boolean isEnabledFor(org.apache.log4j.Priority priority)
           
 boolean isInfoEnabled()
           
 void warn(Object o)
           
 void warn(Object o, Throwable throwable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NShotLogger

public NShotLogger(org.apache.log4j.Logger delegateLogger,
                   int maxTimes)
Creates a NShotLogger that will only output log data if it has been called maxTimes or less.

Parameters:
delegateLogger - the delegate Logger that will do the actual logging
maxTimes - the maximum number of times that the logger can output logging data.
Method Detail

getDelegateLogger

public org.apache.log4j.Logger getDelegateLogger()
Returns:
the underlying delegate Logger

debug

public void debug(Object o)

debug

public void debug(Object o,
                  Throwable throwable)

error

public void error(Object o)

error

public void error(Object o,
                  Throwable throwable)

fatal

public void fatal(Object o)

fatal

public void fatal(Object o,
                  Throwable throwable)

info

public void info(Object o)

info

public void info(Object o,
                 Throwable throwable)

isDebugEnabled

public boolean isDebugEnabled()

isInfoEnabled

public boolean isInfoEnabled()

isEnabledFor

public boolean isEnabledFor(org.apache.log4j.Priority priority)

warn

public void warn(Object o)

warn

public void warn(Object o,
                 Throwable throwable)


Copyright © 2002-2014 Atlassian. All Rights Reserved.