Methods Summary |
---|
public void | addAppender(org.apache.log4j.Appender newAppender)Add appender.
synchronized (appenders) {
appenders.addAppender(newAppender);
}
|
public void | append(org.apache.log4j.spi.LoggingEvent event){@inheritDoc}
//
// if dispatcher thread has died then
// append subsequent events synchronously
// See bug 23021
if ((dispatcher == null) || !dispatcher.isAlive() || (bufferSize <= 0)) {
synchronized (appenders) {
appenders.appendLoopOnAppenders(event);
}
return;
}
// Set the NDC and thread name for the calling thread as these
// LoggingEvent fields were not set at event creation time.
event.getNDC();
event.getThreadName();
// Get a copy of this thread's MDC.
event.getMDCCopy();
if (locationInfo) {
event.getLocationInformation();
}
synchronized (buffer) {
while (true) {
int previousSize = buffer.size();
if (previousSize < bufferSize) {
buffer.add(event);
//
// if buffer had been empty
// signal all threads waiting on buffer
// to check their conditions.
//
if (previousSize == 0) {
buffer.notifyAll();
}
break;
}
//
// Following code is only reachable if buffer is full
//
//
// if blocking and thread is not already interrupted
// and not the dispatcher then
// wait for a buffer notification
boolean discard = true;
if (blocking
&& !Thread.interrupted()
&& Thread.currentThread() != dispatcher) {
try {
buffer.wait();
discard = false;
} catch (InterruptedException e) {
//
// reset interrupt status so
// calling code can see interrupt on
// their next wait or sleep.
Thread.currentThread().interrupt();
}
}
//
// if blocking is false or thread has been interrupted
// add event to discard map.
//
if (discard) {
String loggerName = event.getLoggerName();
DiscardSummary summary = (DiscardSummary) discardMap.get(loggerName);
if (summary == null) {
summary = new DiscardSummary(event);
discardMap.put(loggerName, summary);
} else {
summary.add(event);
}
break;
}
}
}
|
public void | close()Close this AsyncAppender by interrupting the dispatcher
thread which will process all pending events before exiting.
/**
* Set closed flag and notify all threads to check their conditions.
* Should result in dispatcher terminating.
*/
synchronized (buffer) {
closed = true;
buffer.notifyAll();
}
try {
dispatcher.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
org.apache.log4j.helpers.LogLog.error(
"Got an InterruptedException while waiting for the "
+ "dispatcher to finish.", e);
}
//
// close all attached appenders.
//
synchronized (appenders) {
Enumeration iter = appenders.getAllAppenders();
if (iter != null) {
while (iter.hasMoreElements()) {
Object next = iter.nextElement();
if (next instanceof Appender) {
((Appender) next).close();
}
}
}
}
|
public java.util.Enumeration | getAllAppenders()Get iterator over attached appenders.
synchronized (appenders) {
return appenders.getAllAppenders();
}
|
public org.apache.log4j.Appender | getAppender(java.lang.String name)Get appender by name.
synchronized (appenders) {
return appenders.getAppender(name);
}
|
public boolean | getBlocking()Gets whether appender should block calling thread when buffer is full.
If false, messages will be counted by logger and a summary
message appended after the contents of the buffer have been appended.
return blocking;
|
public int | getBufferSize()Gets the current buffer size.
return bufferSize;
|
public boolean | getLocationInfo()Gets whether the location of the logging request call
should be captured.
return locationInfo;
|
public boolean | isAttached(org.apache.log4j.Appender appender)Determines if specified appender is attached.
synchronized (appenders) {
return appenders.isAttached(appender);
}
|
public void | removeAllAppenders()Removes and closes all attached appenders.
synchronized (appenders) {
appenders.removeAllAppenders();
}
|
public void | removeAppender(org.apache.log4j.Appender appender)Removes an appender.
synchronized (appenders) {
appenders.removeAppender(appender);
}
|
public void | removeAppender(java.lang.String name)Remove appender by name.
synchronized (appenders) {
appenders.removeAppender(name);
}
|
public boolean | requiresLayout(){@inheritDoc}
return false;
|
public void | setBlocking(boolean value)Sets whether appender should wait if there is no
space available in the event buffer or immediately return.
synchronized (buffer) {
blocking = value;
buffer.notifyAll();
}
|
public void | setBufferSize(int size)Sets the number of messages allowed in the event buffer
before the calling thread is blocked (if blocking is true)
or until messages are summarized and discarded. Changing
the size will not affect messages already in the buffer.
//
// log4j 1.2 would throw exception if size was negative
// and deadlock if size was zero.
//
if (size < 0) {
throw new java.lang.NegativeArraySizeException("size");
}
synchronized (buffer) {
//
// don't let size be zero.
//
bufferSize = (size < 1) ? 1 : size;
buffer.notifyAll();
}
|
public void | setLocationInfo(boolean flag)The LocationInfo option takes a boolean value. By default, it is
set to false which means there will be no effort to extract the location
information related to the event. As a result, the event that will be
ultimately logged will likely to contain the wrong location information
(if present in the log format).
Location information extraction is comparatively very slow and should be
avoided unless performance is not a concern.
locationInfo = flag;
|