"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.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).

AbstractAppender.java  (apache-log4j-2.11.1-src):AbstractAppender.java  (apache-log4j-2.11.2-src)
skipping to change at line 29 skipping to change at line 29
import java.io.Serializable; import java.io.Serializable;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Objects; import java.util.Objects;
import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.ErrorHandler; import org.apache.logging.log4j.core.ErrorHandler;
import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginConfiguration; import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi red; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi red;
import org.apache.logging.log4j.core.filter.AbstractFilterable; import org.apache.logging.log4j.core.filter.AbstractFilterable;
import org.apache.logging.log4j.core.layout.PatternLayout; import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.util.Integers; import org.apache.logging.log4j.core.util.Integers;
/** /**
* Abstract base class for Appenders. Although Appenders do not have to extend t his class, doing so will simplify their * Abstract base class for Appenders. Although Appenders do not have to extend t his class, doing so will simplify their
skipping to change at line 63 skipping to change at line 64
@PluginElement("Layout") @PluginElement("Layout")
private Layout<? extends Serializable> layout; private Layout<? extends Serializable> layout;
@PluginBuilderAttribute @PluginBuilderAttribute
@Required(message = "No appender name provided") @Required(message = "No appender name provided")
private String name; private String name;
@PluginConfiguration @PluginConfiguration
private Configuration configuration; private Configuration configuration;
public String getName() { public Configuration getConfiguration() {
return name; return configuration;
}
public boolean isIgnoreExceptions() {
return ignoreExceptions;
} }
public Layout<? extends Serializable> getLayout() { public Layout<? extends Serializable> getLayout() {
return layout; return layout;
} }
public B withName(final String name) { public String getName() {
this.name = name; return name;
return asBuilder();
}
public B withIgnoreExceptions(final boolean ignoreExceptions) {
this.ignoreExceptions = ignoreExceptions;
return asBuilder();
}
public B withLayout(final Layout<? extends Serializable> layout) {
this.layout = layout;
return asBuilder();
} }
public Layout<? extends Serializable> getOrCreateLayout() { public Layout<? extends Serializable> getOrCreateLayout() {
if (layout == null) { if (layout == null) {
return PatternLayout.createDefaultLayout(); return PatternLayout.createDefaultLayout();
} }
return layout; return layout;
} }
public Layout<? extends Serializable> getOrCreateLayout(final Charset ch arset) { public Layout<? extends Serializable> getOrCreateLayout(final Charset ch arset) {
if (layout == null) { if (layout == null) {
return PatternLayout.newBuilder().withCharset(charset).build(); return PatternLayout.newBuilder().withCharset(charset).build();
} }
return layout; return layout;
} }
public boolean isIgnoreExceptions() {
return ignoreExceptions;
}
public B setConfiguration(final Configuration configuration) {
this.configuration = configuration;
return asBuilder();
}
public B setIgnoreExceptions(final boolean ignoreExceptions) {
this.ignoreExceptions = ignoreExceptions;
return asBuilder();
}
public B setLayout(final Layout<? extends Serializable> layout) {
this.layout = layout;
return asBuilder();
}
public B setName(final String name) {
this.name = name;
return asBuilder();
}
/** /**
* @deprecated Use {@link #setConfiguration(Configuration)} * @deprecated Use {@link #setConfiguration(Configuration)}
*/ */
@Deprecated @Deprecated
public B withConfiguration(final Configuration configuration) { public B withConfiguration(final Configuration configuration) {
this.configuration = configuration; this.configuration = configuration;
return asBuilder(); return asBuilder();
} }
public B setConfiguration(final Configuration configuration) { /**
this.configuration = configuration; * @deprecated use {@link #setIgnoreExceptions(boolean)}.
return asBuilder(); */
@Deprecated
public B withIgnoreExceptions(final boolean ignoreExceptions) {
return setIgnoreExceptions(ignoreExceptions);
} }
public Configuration getConfiguration() { /**
return configuration; * @deprecated use {@link #setLayout(Layout)}.
*/
@Deprecated
public B withLayout(final Layout<? extends Serializable> layout) {
return setLayout(layout);
}
/**
* @deprecated use {@link #setName(String)}.
*/
@Deprecated
public B withName(final String name) {
return setName(name);
} }
} }
public static int parseInt(final String s, final int defaultValue) {
try {
return Integers.parseInt(s, defaultValue);
} catch (final NumberFormatException e) {
LOGGER.error("Could not parse \"{}\" as an integer, using default v
alue {}: {}", s, defaultValue, e);
return defaultValue;
}
}
private final String name; private final String name;
private final boolean ignoreExceptions; private final boolean ignoreExceptions;
private final Layout<? extends Serializable> layout; private final Layout<? extends Serializable> layout;
private ErrorHandler handler = new DefaultErrorHandler(this); private ErrorHandler handler = new DefaultErrorHandler(this);
/** /**
* Constructor that defaults to suppressing exceptions. * Constructor that defaults to suppressing exceptions.
* *
* @param name The Appender name. * @param name The Appender name.
* @param filter The Filter to associate with the Appender. * @param filter The Filter to associate with the Appender.
* @param layout The layout to use to format the event. * @param layout The layout to use to format the event.
* @deprecated Use {@link #AbstractAppender(String, Filter, Layout, boolean, Property[])}.
*/ */
@Deprecated
protected AbstractAppender(final String name, final Filter filter, final Lay out<? extends Serializable> layout) { protected AbstractAppender(final String name, final Filter filter, final Lay out<? extends Serializable> layout) {
this(name, filter, layout, true); this(name, filter, layout, true, Property.EMPTY_ARRAY);
} }
/** /**
* Constructor. * Constructor.
* *
* @param name The Appender name. * @param name The Appender name.
* @param filter The Filter to associate with the Appender. * @param filter The Filter to associate with the Appender.
* @param layout The layout to use to format the event. * @param layout The layout to use to format the event.
* @param ignoreExceptions If true, exceptions will be logged and suppressed . If false errors will be logged and * @param ignoreExceptions If true, exceptions will be logged and suppressed . If false errors will be logged and
* then passed to the application. * then passed to the application.
* @deprecated Use {@link #AbstractAppender(String, Filter, Layout, boolean, Property[])}
*/ */
@Deprecated
protected AbstractAppender(final String name, final Filter filter, final Lay out<? extends Serializable> layout, protected AbstractAppender(final String name, final Filter filter, final Lay out<? extends Serializable> layout,
final boolean ignoreExceptions) { final boolean ignoreExceptions) {
super(filter); this(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY);
}
/**
* Constructor.
*
* @param name The Appender name.
* @param filter The Filter to associate with the Appender.
* @param layout The layout to use to format the event.
* @param ignoreExceptions If true, exceptions will be logged and suppressed
. If false errors will be logged and
* then passed to the application.
* @since 2.11.2
*/
protected AbstractAppender(final String name, final Filter filter, final Lay
out<? extends Serializable> layout,
final boolean ignoreExceptions, final Property[] properties) {
super(filter, properties);
this.name = Objects.requireNonNull(name, "name"); this.name = Objects.requireNonNull(name, "name");
this.layout = layout; this.layout = layout;
this.ignoreExceptions = ignoreExceptions; this.ignoreExceptions = ignoreExceptions;
} }
public static int parseInt(final String s, final int defaultValue) {
try {
return Integers.parseInt(s, defaultValue);
} catch (final NumberFormatException e) {
LOGGER.error("Could not parse \"{}\" as an integer, using default v
alue {}: {}", s, defaultValue, e);
return defaultValue;
}
}
/** /**
* Handle an error with a message using the {@link ErrorHandler} configured for this Appender. * Handle an error with a message using the {@link ErrorHandler} configured for this Appender.
* *
* @param msg The message. * @param msg The message.
*/ */
public void error(final String msg) { public void error(final String msg) {
handler.error(msg); handler.error(msg);
} }
/** /**
skipping to change at line 247 skipping to change at line 291
/** /**
* The handler must be set before the appender is started. * The handler must be set before the appender is started.
* *
* @param handler The ErrorHandler to use. * @param handler The ErrorHandler to use.
*/ */
@Override @Override
public void setHandler(final ErrorHandler handler) { public void setHandler(final ErrorHandler handler) {
if (handler == null) { if (handler == null) {
LOGGER.error("The handler cannot be set to null"); LOGGER.error("The handler cannot be set to null");
return;
} }
if (isStarted()) { if (isStarted()) {
LOGGER.error("The handler cannot be changed once the appender is sta rted"); LOGGER.error("The handler cannot be changed once the appender is sta rted");
return; return;
} }
this.handler = handler; this.handler = handler;
} }
/** /**
* Serializes the given event using the appender's layout if present. * Serializes the given event using the appender's layout if present.
 End of changes. 16 change blocks. 
36 lines changed or deleted 83 lines changed or added

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