"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/appender/WriterAppender.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

WriterAppender.java  (apache-log4j-2.11.1-src):WriterAppender.java  (apache-log4j-2.11.2-src)
skipping to change at line 25 skipping to change at line 25
* limitations under the license. * limitations under the license.
*/ */
package org.apache.logging.log4j.core.appender; package org.apache.logging.log4j.core.appender;
import java.io.Writer; import java.io.Writer;
import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.Core;
import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.StringLayout; import org.apache.logging.log4j.core.StringLayout;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.layout.PatternLayout; import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.util.CloseShieldWriter; import org.apache.logging.log4j.core.util.CloseShieldWriter;
/** /**
* Appends log events to a {@link Writer}. * Appends log events to a {@link Writer}.
*/ */
@Plugin(name = "Writer", category = Core.CATEGORY_NAME, elementType = Appender.E LEMENT_TYPE, printObject = true) @Plugin(name = "Writer", category = Core.CATEGORY_NAME, elementType = Appender.E LEMENT_TYPE, printObject = true)
public final class WriterAppender extends AbstractWriterAppender<WriterManager> { public final class WriterAppender extends AbstractWriterAppender<WriterManager> {
/** /**
* Builds WriterAppender instances. * Builds WriterAppender instances.
*/ */
public static class Builder implements org.apache.logging.log4j.core.util.Bu public static class Builder<B extends Builder<B>> extends AbstractAppender.B
ilder<WriterAppender> { uilder<B>
implements org.apache.logging.log4j.core.util.Builder<WriterAppender
private Filter filter; > {
private boolean follow = false; private boolean follow = false;
private boolean ignoreExceptions = true;
private StringLayout layout = PatternLayout.createDefaultLayout();
private String name;
private Writer target; private Writer target;
@Override @Override
public WriterAppender build() { public WriterAppender build() {
return new WriterAppender(name, layout, filter, getManager(target, f final StringLayout layout = (StringLayout) getLayout();
ollow, layout), ignoreExceptions); final StringLayout actualLayout = layout != null ? layout : PatternL
} ayout.createDefaultLayout();
return new WriterAppender(getName(), actualLayout, getFilter(), getM
public Builder setFilter(final Filter aFilter) { anager(target, follow, actualLayout),
this.filter = aFilter; isIgnoreExceptions(), getPropertyArray());
return this;
} }
public Builder setFollow(final boolean shouldFollow) { public B setFollow(final boolean shouldFollow) {
this.follow = shouldFollow; this.follow = shouldFollow;
return this; return asBuilder();
}
public Builder setIgnoreExceptions(final boolean shouldIgnoreExceptions)
{
this.ignoreExceptions = shouldIgnoreExceptions;
return this;
}
public Builder setLayout(final StringLayout aLayout) {
this.layout = aLayout;
return this;
}
public Builder setName(final String aName) {
this.name = aName;
return this;
} }
public Builder setTarget(final Writer aTarget) { public B setTarget(final Writer aTarget) {
this.target = aTarget; this.target = aTarget;
return this; return asBuilder();
} }
} }
/** /**
* Holds data to pass to factory method. * Holds data to pass to factory method.
*/ */
private static class FactoryData { private static class FactoryData {
private final StringLayout layout; private final StringLayout layout;
private final String name; private final String name;
private final Writer writer; private final Writer writer;
skipping to change at line 163 skipping to change at line 140
@PluginFactory @PluginFactory
public static WriterAppender createAppender(StringLayout layout, final Filte r filter, final Writer target, public static WriterAppender createAppender(StringLayout layout, final Filte r filter, final Writer target,
final String name, final boolean follow, final boolean ignore) { final String name, final boolean follow, final boolean ignore) {
if (name == null) { if (name == null) {
LOGGER.error("No name provided for WriterAppender"); LOGGER.error("No name provided for WriterAppender");
return null; return null;
} }
if (layout == null) { if (layout == null) {
layout = PatternLayout.createDefaultLayout(); layout = PatternLayout.createDefaultLayout();
} }
return new WriterAppender(name, layout, filter, getManager(target, follo w, layout), ignore); return new WriterAppender(name, layout, filter, getManager(target, follo w, layout), ignore, null);
} }
private static WriterManager getManager(final Writer target, final boolean f ollow, final StringLayout layout) { private static WriterManager getManager(final Writer target, final boolean f ollow, final StringLayout layout) {
final Writer writer = new CloseShieldWriter(target); final Writer writer = new CloseShieldWriter(target);
final String managerName = target.getClass().getName() + "@" + Integer.t oHexString(target.hashCode()) + '.' final String managerName = target.getClass().getName() + "@" + Integer.t oHexString(target.hashCode()) + '.'
+ follow; + follow;
return WriterManager.getManager(managerName, new FactoryData(writer, man agerName, layout), factory); return WriterManager.getManager(managerName, new FactoryData(writer, man agerName, layout), factory);
} }
@PluginBuilderFactory @PluginBuilderFactory
public static Builder newBuilder() { public static <B extends Builder<B>> B newBuilder() {
return new Builder(); return new Builder<B>().asBuilder();
} }
private WriterAppender(final String name, final StringLayout layout, final F ilter filter, private WriterAppender(final String name, final StringLayout layout, final F ilter filter,
final WriterManager manager, final boolean ignoreExceptions) { final WriterManager manager, final boolean ignoreExceptions, final P
super(name, layout, filter, ignoreExceptions, true, manager); roperty[] properties) {
super(name, layout, filter, ignoreExceptions, true, properties, manager)
;
} }
} }
 End of changes. 11 change blocks. 
42 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)