Skip to content

Commit

Permalink
[PAXLOGGING-312] Upgrade to log4j2 2.13.2 with necessary changes rela…
Browse files Browse the repository at this point in the history
…ted to LOG4J2-2779

(cherry picked from commit 5f9d55d)
  • Loading branch information
grgrzybek committed May 4, 2020
1 parent feebe09 commit f2fb938
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,20 @@ private void setFields(final MapMessage<?, ?> mapMessage) throws SQLException {
* Sets the given Object in the prepared statement. The value is truncated if needed.
*/
private void setStatementObject(final int j, final String nameKey, final Object value) throws SQLException {
statement.setObject(j, truncate(nameKey, value));
if (statement == null) {
throw new AppenderLoggingException("Cannot set a value when the PreparedStatement is null.");
}
if (value == null) {
if (columnMetaData == null) {
throw new AppenderLoggingException("Cannot set a value when the column metadata is null.");
}
// [LOG4J2-2762] [JDBC] MS-SQL Server JDBC driver throws SQLServerException when
// inserting a null value for a VARBINARY column.
// Calling setNull() instead of setObject() for null values fixes [LOG4J2-2762].
this.statement.setNull(j, columnMetaData.get(nameKey).getType());
} else {
statement.setObject(j, truncate(nameKey, value));
}
}

@Override
Expand Down Expand Up @@ -822,13 +835,7 @@ protected void writeInternal(final LogEvent event, final Serializable serializab
} else {
final Object value = TypeConverters.convert(layout.toSerializable(event),
mapping.getType(), null);
if (value == null) {
// TODO We might need to always initialize the columnMetaData to specify the
// type.
this.statement.setNull(j++, Types.NULL);
} else {
setStatementObject(j++, mapping.getNameKey(), value);
}
setStatementObject(j++, mapping.getNameKey(), value);
}
}
}
Expand All @@ -854,10 +861,15 @@ protected void writeInternal(final LogEvent event, final Serializable serializab
}

if (isBuffered() && this.isBatchSupported) {
logger().debug("addBatch for {}", this.statement);
this.statement.addBatch();
} else if (this.statement.executeUpdate() == 0) {
throw new AppenderLoggingException(
"No records inserted in database table for log event in JDBC manager [%s].", fieldsToString());
} else {
final int executeUpdate = this.statement.executeUpdate();
logger().debug("executeUpdate = {} for {}", executeUpdate, this.statement);
if (executeUpdate == 0) {
throw new AppenderLoggingException(
"No records inserted in database table for log event in JDBC manager [%s].", fieldsToString());
}
}
} catch (final SQLException e) {
throw new DbAppenderLoggingException(e, "Failed to insert record for log event in JDBC manager: %s [%s]", e,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.util.FileUtils;
Expand All @@ -44,7 +43,7 @@ public class StatusConfiguration {
private static final Level DEFAULT_STATUS = Level.ERROR;
private static final Verbosity DEFAULT_VERBOSITY = Verbosity.QUIET;

private final Collection<String> errorMessages = Collections.synchronizedCollection(new LinkedList<String>());
private final Collection<String> errorMessages = new LinkedBlockingQueue<String>();
private final StatusLogger logger = StatusLogger.getLogger();

private volatile boolean initialized = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.Map;
import java.util.Properties;

import org.apache.logging.log4j.core.impl.ThreadContextDataInjector;
import org.apache.logging.log4j.core.impl.ThreadContextDataProvider;
import org.apache.logging.log4j.core.lookup.StrSubstitutor;
import org.apache.logging.log4j.status.StatusLogger;
import org.ops4j.pax.logging.EventAdminPoster;
Expand Down Expand Up @@ -82,6 +84,9 @@ public void start(BundleContext bundleContext) throws Exception {

boolean cm = BackendSupport.isConfigurationAdminAvailable();

ThreadContextDataInjector.contextDataProviders.clear();
ThreadContextDataInjector.contextDataProviders.add(new ThreadContextDataProvider());

if (!cm) {
StatusLogger.getLogger().info("Configuration Admin is not available.");
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<version.org.apache.felix.configadmin>1.9.16</version.org.apache.felix.configadmin>
<version.org.apache.felix.framework>5.6.12</version.org.apache.felix.framework>
<version.org.apache.felix6.framework>6.0.3</version.org.apache.felix6.framework>
<version.org.apache.logging.log4j>2.13.1</version.org.apache.logging.log4j>
<version.org.apache.logging.log4j>2.13.2</version.org.apache.logging.log4j>
<version.org.apache.servicemix.bundles.javax-inject>1_3</version.org.apache.servicemix.bundles.javax-inject>
<version.org.jboss.logging>3.4.1.Final</version.org.jboss.logging>
<version.org.mockito>3.1.0</version.org.mockito>
Expand Down

0 comments on commit f2fb938

Please sign in to comment.