Details
Description
I'm programmatically updating the configuration after it has been created
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); final Configuration config = ctx.getConfiguration(); ColumnConfig[] columnConfig = new ColumnConfig[0]; ColumnMapping[] columnMappings = new ColumnMapping[1]; columnMappings[0] = ColumnMapping.newBuilder() .setLiteral("'TEST_STRING'") .build(); FactoryMethodConnectionSource myConnectionSource = FactoryMethodConnectionSource.createConnectionSource( "com.ConnectionFactory", "getConnection"); Appender appender = org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender.newBuilder() .setTableName("MSG_LOG") .setConfiguration(config) .setColumnMappings(columnMappings) .setColumnConfigs(columnConfig) .setConnectionSource(myConnectionSource) .withName("db-appender") .build(); appender.start(); config.addAppender(appender); Map<String, LoggerConfig> loggers = config.getLoggers(); loggers.forEach((loggerName, loggerConfig) -> { loggerConfig.addAppender(appender, org.apache.logging.log4j.Level.INFO, null); config.addLogger("org.apache.logging.log4j", loggerConfig); }); ctx.updateLoggers();
Creates JdbcDatabaseManager with sqlStatement
INSERT INTO MSG_LOG (null) VALUES ('TEST_STRING'?)
As you can see, PARAMETER_MARKER "?" gets added.
Later in writeInternal method, there is a check for layout without an else condition
if (layout != null) //line 164 of JdbcDatabaseManager
Layout is null for my column so the parameter never get's set for the PreparedStatement which will throw an error
Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 1 at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2086) at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:9713) at oracle.jdbc.driver.OraclePreparedStatementWrapper.addBatch(OraclePreparedStatementWrapper.java:1067) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.addBatch(HikariProxyPreparedStatement.java) at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:199) ... 65 more
So, we could create the sqlStatement without the ParameterMarker "?" or perhaps just make sure it gets set to null.
I would be open to making a PR if this is an issue and other can reproduce.