Re: Strange error using code to set up JDBC logger

Gary Gregory <[email protected]>
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <CACZkXPzkjykeifkHoR+N2=sCUuc_OvOdLXG55gB1L5fB=0Q8JA@mail.gmail.com>
The first thing I would say is please make sure you are using the current
version 2.14.1.

Gary


On Wed, Aug 11, 2021, 11:34 Martin Fernau <[email protected]>
wrote:

> Hello,
>
> I'm having the same problem and wonder if there is a complete example of
> how to configure a JDBC Appender programmatically.
>
> I'm too getting the exception "Arguments given for element JDBC are
> invalid: field 'connectionSource' has invalid value 'null'".
>
> Thanks
> Martin
>
> On 2019/03/18 15:00:04, Arnold Morein <[email protected]> wrote:
>  > I am trying to configure a JDBC logger via code (no problems using it
> from XML file).
>  >
>  > I'm using Log4j2 version 2.11.2. What examples I can find are vague,
> incomplete, or not related.
>  >
>  > I'm finding code that may be for log4j1 and log4-jdbc but no jars in
> mvnrepository.com so is that old and deprecated now too?
>  >
>  > I have:
>  >
>  > log4j-1.2-api-2.11.2.jar
>  > log4j-api-2.11.2.jar
>  > log4j-core-2.11.2.jar
>  > log4j-over-slf4j-1.7.2.jar
>  > log4j-slf4j-impl-2.11.2.jar
>  > log4j-web-2.11.2.jar
>  > slf4j-api-1.7.26.jar
>  >
>  > in a war project.
>  >
>  > In a nut shell, the following code
>  >
>  >         ColumnConfig[] columnConfigsArray = columnConfigs.toArray(new
> ColumnConfig[columnConfigs.size()]);
>  >
>  >         JNDIConnectionSource connectionSource = new
> JNDIConnectionSource();
>  >
>
> connectionSource.setJndiLocation(activityLogConfiguration.getDataSourceUrl());
>  >
>  >         AppenderComponentBuilder appenderBuilder =
> configBuilder.newAppender(ACTIVITY_LOG_APPENDER, "JDBC")
>  >             .addAttribute("connectionSource", connectionSource)
>  >             .addAttribute("columnConfigs", columnConfigsArray)
>  >             .addAttribute("tableName",
> activityLogConfiguration.getSchemaNameAndTableName())
>  >             .addAttribute("bufferSize",
> activityLogConfiguration.getBufferSize());
>  >
>  >         // complete the configuration
>  >         appenderBuilder.build();
>  >
>  >         // build the logger and add to the appender
>  >         AppenderRefComponentBuilder appenderRef =
> configBuilder.newAppenderRef(ACTIVITY_LOG_APPENDER);
>  >
>  >         LoggerComponentBuilder logger =
> configBuilder.newLogger(ACTIVITY_LOG_APPENDER, Level.INFO);
>  >         logger.add(appenderRef);
>  >         logger.build();
>  >
>  >         configBuilder.add(logger);
>  >
>  > always results in:
>  >
>  > 09:55:16,864 INFO  [stdout] (ServerService Thread Pool -- 77)
> 2019-03-18 09:55:16,863 ServerService Thread Pool -- 77 ERROR No
> ConnectionSource provided: connectionSource
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)
> 2019-03-18 09:55:16,873 ServerService Thread Pool -- 77 ERROR Could not
> create plugin of type class
> org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender for element
> JDBC org.apache.logging.log4j.core.config.ConfigurationException:
> Arguments given for element JDBC are invalid: field 'connectionSource'
> has invalid value 'null'
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:209)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:204)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:161)
>  > 09:55:16,877 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:57)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> gov.texas.dps.itd.ias.app.logging.config.ConfigureActivityLog4j.configureLoggingForEnvironment(ConfigureActivityLog4j.java:61)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> gov.texas.dps.aamva.mock.startup.StartupServletListener.contextInitialized(StartupServletListener.java:47)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:217)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:186)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:251)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:96)
>  > 09:55:16,878 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:78)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
> java.util.concurrent.FutureTask.run(FutureTask.java:266)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
>
> org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
> java.lang.Thread.run(Thread.java:748)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)     at
> org.jboss.threads.JBossThread.run(JBossThread.java:485)
>  > 09:55:16,879 INFO  [stdout] (ServerService Thread Pool -- 77)
>  > 09:55:16,884 INFO  [stdout] (ServerService Thread Pool -- 77)
> 2019-03-18 09:55:16,884 ServerService Thread Pool -- 77 ERROR Null
> object returned for JDBC in Appenders.
>  > 09:55:16,885 INFO  [stdout] (ServerService Thread Pool -- 77)
> 2019-03-18 09:55:16,885 ServerService Thread Pool -- 77 ERROR Unable to
> locate appender "ACTIVITY_LOGGER" for logger config "ACTIVITY_LOGGER"
>  >
>  > But the connectionSource object I'm passing is is NOT null.
>  >
>  > What am I missing?
>  >
>  >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.