JDBCAppender fails to pass connection URL string

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

JDBCAppender fails to pass connection URL string

Alban Hertroys
Hi,

We're having a lot of trouble getting the JDBCAppender to write to our
PostgreSQL database. There's probably a configuration error somewhere, but
we haven't been able to find it. And I have been searching and trying for
several days now, with no progress at all.
Even though we specify a connection URL in the JDNI source (see below), it
always ends with the JDBCAppender complaining that:
        java.sql.SQLException: Cannot create JDBC driver of class '' for
connect URL 'null'

The Appender should write the data to our database at server "foobar",
database "logging-tst". Using the same credentials in SquirrelSQL, with
the same JDBC driver, I can connect to that database and query the table
specified in the log4j.xml (schema: "logging", table: "usage"; names being
case-insensitive).

Any pointers would be appreciated.

Environment:
- Centos 7
- Apache Tomcat 8.5.32
- log4j-2.11

We created a servlet HTTP filter into a JAR, compiled against:
WEB-INF/lib:
        log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
        servlet-api.jar

This servlet put()'s certain fields into the ThreadContext, which we then
attempt to access through %X{...} in the log4j2.xml, appending those
fields as a
row to an existing table in our database.
We had this set-up working previously with log4j-1.something in an MS SQL
'05
DB, all on Windows 2003 server (which we are migrating away from due to
performance issues).

Files within the web application:
WEB-INF/lib/
        log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
        postgresql-jdbc.jar


META-INF/context.xml:
---------------------
<?xml version="1.0" encoding="utf-8"?>
<context>
    <resource
        name="jdbc/loggingtst"
        auth="Container"
        type="javax.sql.DataSource"
        username="*****"
        password="*****"
        driverClassName="org.postgresql.Driver"
        url="jdbc:postgresql://foobar:5432/logging-tst"
        maxTotal="20"
        maxIdle="10"
    />
</context>


WEB-INF/classes/log4j2.xml:
---------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
        ...
    <Appenders>
                ...
        <JDBC name="DBAppender" tableName="logging.usage">
            <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
            <Column name="servername"   pattern="%X{servername}"/>
            <Column name="fex"          pattern="%X{focexec}"/>
            <Column name="parameters"   pattern="%X{parameters}"/>
            <Column name="username"     pattern="%X{username}"/>
            <Column name="duration"     pattern="%X{duration}"/>
            <Column name="user_agent"   pattern="%X{user-agent}"/>
        </JDBC>
    </Appenders>
    <Loggers>
                ...
        <Logger name="LogFilter" level="info" additivity="false">
            <AppenderRef ref="DBAppender"/>
        </Logger>

        <Root level="error">
            <AppenderRef ref="sysout" />
        </Root>
    </Loggers>

</Configuration>


WEB-INF/web.xml:
----------------
  ...
  <resource-ref>
    <description>PostgreSQL logging table</description>
    <res-ref-name>jdbc/loggingtst</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
  ...

With this, catalina.out contains:

2019-12-09 17:38:16,460 localhost-startStop-1 ERROR JdbcDatabaseManager
JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
columnConfigs=[{ name=servername, layout=%X{servername}, literal=null,
timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
timestamp=false }, { name=parameters, layout=%X{parameters}, literal=null,
timestamp=false }, { name=username, layout=%X{username}, literal=null,
timestamp=false }, { name=duration, layout=%X{duration}, literal=null,
timestamp=false }, { name=user_agent, layout=%X{user-agent}, literal=null,
timestamp=false }], columnMappings=[]} Could not perform database startup
operations: java.sql.SQLException: Cannot create JDBC driver of class ''
for connect URL 'null' java.sql.SQLException: Cannot create JDBC driver of
class '' for connect URL 'null'
        at
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2186)
        at
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2066)
        at
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1525)
        at
org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection(DataSourceConnectionSource.java:51)
        at
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal(JdbcDatabaseManager.java:85)
        at
org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup(AbstractDatabaseManager.java:81)
        at
org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start(AbstractDatabaseAppender.java:106)
        at
org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:265)
        at
org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
        at
org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
        at
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:240)
        at
org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:158)
        at
org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi(Log4jWebInitializerImpl.java:168)
        at
org.apache.logging.log4j.web.Log4jWebInitializerImpl.start(Log4jWebInitializerImpl.java:110)
        at
org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:57)
        at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
        at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
        at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
        at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
        at
org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)
        at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
        at org.postgresql.Driver.parseURL(Driver.java:551)
        at org.postgresql.Driver.acceptsURL(Driver.java:472)
        at java.sql.DriverManager.getDriver(DriverManager.java:299)
        at
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2171)
        ... 26 more

(Ignore below company statement)



Alban  Hertroys    
D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E: [hidden email]
Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
Netherlands
Chamber of Commerce number: 34223268

 
       
                 
The information contained in this e-mail is intended solely for the use of the
individual or entity to whom it is addressed. If you are not the intended
recipient, you are hereby notified that any disclosure, copying, distribution
or action in relation to the contents of this information is strictly
prohibited and may be unlawful and request you to delete this message and any
attachments and advise the sender by return e-mail. The confidentiality of this
message is not warranted. Apollo Vredestein and its subsidiaries rule out any
and every liability resulting from this or any other electronic transmission



       
               
           Please consider the environment before printing this e-mail


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: JDBCAppender fails to pass connection URL string

Gary Gregory-4
AFK, sorry for the top-post. Have you looked at our unit tests? There might
be something there to help see what the usage pattern is for JNDI.

Gary

On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
[hidden email]> wrote:

> Hi,
>
> We're having a lot of trouble getting the JDBCAppender to write to our
> PostgreSQL database. There's probably a configuration error somewhere, but
> we haven't been able to find it. And I have been searching and trying for
> several days now, with no progress at all.
> Even though we specify a connection URL in the JDNI source (see below), it
> always ends with the JDBCAppender complaining that:
>         java.sql.SQLException: Cannot create JDBC driver of class '' for
> connect URL 'null'
>
> The Appender should write the data to our database at server "foobar",
> database "logging-tst". Using the same credentials in SquirrelSQL, with
> the same JDBC driver, I can connect to that database and query the table
> specified in the log4j.xml (schema: "logging", table: "usage"; names being
> case-insensitive).
>
> Any pointers would be appreciated.
>
> Environment:
> - Centos 7
> - Apache Tomcat 8.5.32
> - log4j-2.11
>
> We created a servlet HTTP filter into a JAR, compiled against:
> WEB-INF/lib:
>         log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
>         servlet-api.jar
>
> This servlet put()'s certain fields into the ThreadContext, which we then
> attempt to access through %X{...} in the log4j2.xml, appending those
> fields as a
> row to an existing table in our database.
> We had this set-up working previously with log4j-1.something in an MS SQL
> '05
> DB, all on Windows 2003 server (which we are migrating away from due to
> performance issues).
>
> Files within the web application:
> WEB-INF/lib/
>         log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
>         postgresql-jdbc.jar
>
>
> META-INF/context.xml:
> ---------------------
> <?xml version="1.0" encoding="utf-8"?>
> <context>
>     <resource
>         name="jdbc/loggingtst"
>         auth="Container"
>         type="javax.sql.DataSource"
>         username="*****"
>         password="*****"
>         driverClassName="org.postgresql.Driver"
>         url="jdbc:postgresql://foobar:5432/logging-tst"
>         maxTotal="20"
>         maxIdle="10"
>     />
> </context>
>
>
> WEB-INF/classes/log4j2.xml:
> ---------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN">
>         ...
>     <Appenders>
>                 ...
>         <JDBC name="DBAppender" tableName="logging.usage">
>             <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
>             <Column name="servername"   pattern="%X{servername}"/>
>             <Column name="fex"          pattern="%X{focexec}"/>
>             <Column name="parameters"   pattern="%X{parameters}"/>
>             <Column name="username"     pattern="%X{username}"/>
>             <Column name="duration"     pattern="%X{duration}"/>
>             <Column name="user_agent"   pattern="%X{user-agent}"/>
>         </JDBC>
>     </Appenders>
>     <Loggers>
>                 ...
>         <Logger name="LogFilter" level="info" additivity="false">
>             <AppenderRef ref="DBAppender"/>
>         </Logger>
>
>         <Root level="error">
>             <AppenderRef ref="sysout" />
>         </Root>
>     </Loggers>
>
> </Configuration>
>
>
> WEB-INF/web.xml:
> ----------------
>   ...
>   <resource-ref>
>     <description>PostgreSQL logging table</description>
>     <res-ref-name>jdbc/loggingtst</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
>   </resource-ref>
>   ...
>
> With this, catalina.out contains:
>
> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR JdbcDatabaseManager
> JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
> columnConfigs=[{ name=servername, layout=%X{servername}, literal=null,
> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
> timestamp=false }, { name=parameters, layout=%X{parameters}, literal=null,
> timestamp=false }, { name=username, layout=%X{username}, literal=null,
> timestamp=false }, { name=duration, layout=%X{duration}, literal=null,
> timestamp=false }, { name=user_agent, layout=%X{user-agent}, literal=null,
> timestamp=false }], columnMappings=[]} Could not perform database startup
> operations: java.sql.SQLException: Cannot create JDBC driver of class ''
> for connect URL 'null' java.sql.SQLException: Cannot create JDBC driver of
> class '' for connect URL 'null'
>         at
>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2186)
>         at
>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2066)
>         at
>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1525)
>         at
>
> org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection(DataSourceConnectionSource.java:51)
>         at
>
> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal(JdbcDatabaseManager.java:85)
>         at
>
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup(AbstractDatabaseManager.java:81)
>         at
>
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start(AbstractDatabaseAppender.java:106)
>         at
>
> org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:265)
>         at
>
> org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
>         at
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
>         at
>
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:240)
>         at
>
> org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:158)
>         at
>
> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi(Log4jWebInitializerImpl.java:168)
>         at
>
> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start(Log4jWebInitializerImpl.java:110)
>         at
>
> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:57)
>         at
>
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
>         at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>         at
>
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
>         at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
>         at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
>         at
>
> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
>         at
>
> org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>         at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>         at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>         at java.lang.Thread.run(Thread.java:748)
> Caused by: java.lang.NullPointerException
>         at org.postgresql.Driver.parseURL(Driver.java:551)
>         at org.postgresql.Driver.acceptsURL(Driver.java:472)
>         at java.sql.DriverManager.getDriver(DriverManager.java:299)
>         at
>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2171)
>         ... 26 more
>
> (Ignore below company statement)
>
>
>
> Alban  Hertroys
> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> [hidden email]
> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
> Netherlands
> Chamber of Commerce number: 34223268
>
>
>
>
> The information contained in this e-mail is intended solely for the use of
> the
> individual or entity to whom it is addressed. If you are not the intended
> recipient, you are hereby notified that any disclosure, copying,
> distribution
> or action in relation to the contents of this information is strictly
> prohibited and may be unlawful and request you to delete this message and
> any
> attachments and advise the sender by return e-mail. The confidentiality of
> this
> message is not warranted. Apollo Vredestein and its subsidiaries rule out
> any
> and every liability resulting from this or any other electronic
> transmission
>
>
>
>
>
>            Please consider the environment before printing this e-mail
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Re: JDBCAppender fails to pass connection URL string

Alban Hertroys
"Gary Gregory" <[hidden email]> wrote on 2019-12-11 22:01:54:

> CAUTION : External email. Do not click links or open  attachments
> unless you recognize the sender and know the content is safe.
>
> AFK, sorry for the top-post. Have you looked at our unit tests? There
might
> be something there to help see what the usage pattern is for JNDI.

You mean to say I should write some Java code to test the JNDI connection
as defined in the Tomcat configuration? Or are the unit tests you refer to
existing code that is available somewhere?

Either way, I have no idea which unit tests you're referring to? I'm also
not quite sure what I'm looking for here, I haven't done this before and I
don't write Java code on a regular basis. Just created a few snippets to
do small stuff here and there, such as this case where we're wrapping a
servlet to have some logging of HTTP context information to a database
table.

There's no requirement here to do the logging through JNDI either; we used
a direct connection through log4j.xml previously and that had some issues
(mostly losing connection when the DB server got kicked). JNDI just seemed
to be the easiest way to set up a connection pool for the JDBCAppender,
but now it's starting to look like JNDI is anything but.

Regards,
Alban.


> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
> [hidden email]> wrote:
>
> > Hi,
> >
> > We're having a lot of trouble getting the JDBCAppender to write to our
> > PostgreSQL database. There's probably a configuration error somewhere,
but
> > we haven't been able to find it. And I have been searching and trying
for
> > several days now, with no progress at all.
> > Even though we specify a connection URL in the JDNI source (see
below), it
> > always ends with the JDBCAppender complaining that:
> >         java.sql.SQLException: Cannot create JDBC driver of class ''
for
> > connect URL 'null'
> >
> > The Appender should write the data to our database at server "foobar",
> > database "logging-tst". Using the same credentials in SquirrelSQL,
with
> > the same JDBC driver, I can connect to that database and query the
table
> > specified in the log4j.xml (schema: "logging", table: "usage"; names
being

> > case-insensitive).
> >
> > Any pointers would be appreciated.
> >
> > Environment:
> > - Centos 7
> > - Apache Tomcat 8.5.32
> > - log4j-2.11
> >
> > We created a servlet HTTP filter into a JAR, compiled against:
> > WEB-INF/lib:
> >         log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
> >         servlet-api.jar
> >
> > This servlet put()'s certain fields into the ThreadContext, which we
then
> > attempt to access through %X{...} in the log4j2.xml, appending those
> > fields as a
> > row to an existing table in our database.
> > We had this set-up working previously with log4j-1.something in an MS
SQL
> > '05
> > DB, all on Windows 2003 server (which we are migrating away from due
to

> > performance issues).
> >
> > Files within the web application:
> > WEB-INF/lib/
> >         log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
> > log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
> > log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
> >         postgresql-jdbc.jar
> >
> >
> > META-INF/context.xml:
> > ---------------------
> > <?xml version="1.0" encoding="utf-8"?>
> > <context>
> >     <resource
> >         name="jdbc/loggingtst"
> >         auth="Container"
> >         type="javax.sql.DataSource"
> >         username="*****"
> >         password="*****"
> >         driverClassName="org.postgresql.Driver"
> >         url="jdbc:postgresql://foobar:5432/logging-tst"
> >         maxTotal="20"
> >         maxIdle="10"
> >     />
> > </context>
> >
> >
> > WEB-INF/classes/log4j2.xml:
> > ---------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Configuration status="WARN">
> >         ...
> >     <Appenders>
> >                 ...
> >         <JDBC name="DBAppender" tableName="logging.usage">
> >             <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
> >             <Column name="servername"   pattern="%X{servername}"/>
> >             <Column name="fex"          pattern="%X{focexec}"/>
> >             <Column name="parameters"   pattern="%X{parameters}"/>
> >             <Column name="username"     pattern="%X{username}"/>
> >             <Column name="duration"     pattern="%X{duration}"/>
> >             <Column name="user_agent"   pattern="%X{user-agent}"/>
> >         </JDBC>
> >     </Appenders>
> >     <Loggers>
> >                 ...
> >         <Logger name="LogFilter" level="info" additivity="false">
> >             <AppenderRef ref="DBAppender"/>
> >         </Logger>
> >
> >         <Root level="error">
> >             <AppenderRef ref="sysout" />
> >         </Root>
> >     </Loggers>
> >
> > </Configuration>
> >
> >
> > WEB-INF/web.xml:
> > ----------------
> >   ...
> >   <resource-ref>
> >     <description>PostgreSQL logging table</description>
> >     <res-ref-name>jdbc/loggingtst</res-ref-name>
> >     <res-type>javax.sql.DataSource</res-type>
> >     <res-auth>Container</res-auth>
> >   </resource-ref>
> >   ...
> >
> > With this, catalina.out contains:
> >
> > 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
JdbcDatabaseManager
> > JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
> > columnConfigs=[{ name=servername, layout=%X{servername}, literal=null,
> > timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
> > timestamp=false }, { name=parameters, layout=%X{parameters},
literal=null,
> > timestamp=false }, { name=username, layout=%X{username}, literal=null,
> > timestamp=false }, { name=duration, layout=%X{duration}, literal=null,
> > timestamp=false }, { name=user_agent, layout=%X{user-agent},
literal=null,
> > timestamp=false }], columnMappings=[]} Could not perform database
startup
> > operations: java.sql.SQLException: Cannot create JDBC driver of class
''
> > for connect URL 'null' java.sql.SQLException: Cannot create JDBC
driver of

> > class '' for connect URL 'null'
> >         at
> >
> >
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> (BasicDataSource.java:2186)
> >         at
> >
> > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
> (BasicDataSource.java:2066)
> >         at
> >
> > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
> (BasicDataSource.java:1525)
> >         at
> >
> >
>
org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
> (DataSourceConnectionSource.java:51)
> >         at
> >
> >
>
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
> (JdbcDatabaseManager.java:85)
> >         at
> >
> >
>
org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup

> (AbstractDatabaseManager.java:81)
> >         at
> >
> >
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
> (AbstractDatabaseAppender.java:106)
> >         at
> >
> > org.apache.logging.log4j.core.config.AbstractConfiguration.start
> (AbstractConfiguration.java:265)
> >         at
> >
> > org.apache.logging.log4j.core.LoggerContext.setConfiguration
> (LoggerContext.java:547)
> >         at
> >
org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)

> >         at
> >
> > org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
> (Log4jContextFactory.java:240)
> >         at
> >
> > org.apache.logging.log4j.core.config.Configurator.initialize
> (Configurator.java:158)
> >         at
> >
> >
> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
> (Log4jWebInitializerImpl.java:168)
> >         at
> >
> > org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
> (Log4jWebInitializerImpl.java:110)
> >         at
> >
> >
> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
> (Log4jServletContainerInitializer.java:57)
> >         at
> >
> > org.apache.catalina.core.StandardContext.startInternal
> (StandardContext.java:5245)
> >         at
> > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >         at
> >
> > org.apache.catalina.core.ContainerBase.addChildInternal
> (ContainerBase.java:754)
> >         at
> >
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
> >         at
> > org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
> >         at
> >
> >
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
> >         at
> >
> > org.apache.catalina.startup.HostConfig$DeployDescriptor.run
> (HostConfig.java:1839)
> >         at
> >
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

> >         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> >         at
> >
> > java.util.concurrent.ThreadPoolExecutor.runWorker
> (ThreadPoolExecutor.java:1149)
> >         at
> >
> > java.util.concurrent.ThreadPoolExecutor$Worker.run
> (ThreadPoolExecutor.java:624)
> >         at java.lang.Thread.run(Thread.java:748)
> > Caused by: java.lang.NullPointerException
> >         at org.postgresql.Driver.parseURL(Driver.java:551)
> >         at org.postgresql.Driver.acceptsURL(Driver.java:472)
> >         at java.sql.DriverManager.getDriver(DriverManager.java:299)
> >         at
> >
> >
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> (BasicDataSource.java:2171)
> >         ... 26 more
> >
> > (Ignore below company statement)
> >
> >
> >
> > Alban  Hertroys
> > D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> > [hidden email]
> > Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
The
> > Netherlands
> > Chamber of Commerce number: 34223268
> >
> >
> >
> >
> > The information contained in this e-mail is intended solely for the
use of
> > the
> > individual or entity to whom it is addressed. If you are not the
intended
> > recipient, you are hereby notified that any disclosure, copying,
> > distribution
> > or action in relation to the contents of this information is strictly
> > prohibited and may be unlawful and request you to delete this message
and
> > any
> > attachments and advise the sender by return e-mail. The
confidentiality of
> > this
> > message is not warranted. Apollo Vredestein and its subsidiaries rule
out

> > any
> > and every liability resulting from this or any other electronic
> > transmission
> >
> >
> >
> >
> >
> >            Please consider the environment before printing this e-mail
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >


Alban  Hertroys    
D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E: [hidden email]
Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
Netherlands
Chamber of Commerce number: 34223268

 
       
                 
The information contained in this e-mail is intended solely for the use of the
individual or entity to whom it is addressed. If you are not the intended
recipient, you are hereby notified that any disclosure, copying, distribution
or action in relation to the contents of this information is strictly
prohibited and may be unlawful and request you to delete this message and any
attachments and advise the sender by return e-mail. The confidentiality of this
message is not warranted. Apollo Vredestein and its subsidiaries rule out any
and every liability resulting from this or any other electronic transmission



       
               
           Please consider the environment before printing this e-mail


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: JDBCAppender fails to pass connection URL string

Matt Sicker
Unit tests in the log4j project. All our components have examples in unit
tests.

On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
[hidden email]> wrote:

> "Gary Gregory" <[hidden email]> wrote on 2019-12-11 22:01:54:
>
> > CAUTION : External email. Do not click links or open  attachments
> > unless you recognize the sender and know the content is safe.
> >
> > AFK, sorry for the top-post. Have you looked at our unit tests? There
> might
> > be something there to help see what the usage pattern is for JNDI.
>
> You mean to say I should write some Java code to test the JNDI connection
> as defined in the Tomcat configuration? Or are the unit tests you refer to
> existing code that is available somewhere?
>
> Either way, I have no idea which unit tests you're referring to? I'm also
> not quite sure what I'm looking for here, I haven't done this before and I
> don't write Java code on a regular basis. Just created a few snippets to
> do small stuff here and there, such as this case where we're wrapping a
> servlet to have some logging of HTTP context information to a database
> table.
>
> There's no requirement here to do the logging through JNDI either; we used
> a direct connection through log4j.xml previously and that had some issues
> (mostly losing connection when the DB server got kicked). JNDI just seemed
> to be the easiest way to set up a connection pool for the JDBCAppender,
> but now it's starting to look like JNDI is anything but.
>
> Regards,
> Alban.
>
>
> > On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
> > [hidden email]> wrote:
> >
> > > Hi,
> > >
> > > We're having a lot of trouble getting the JDBCAppender to write to our
> > > PostgreSQL database. There's probably a configuration error somewhere,
> but
> > > we haven't been able to find it. And I have been searching and trying
> for
> > > several days now, with no progress at all.
> > > Even though we specify a connection URL in the JDNI source (see
> below), it
> > > always ends with the JDBCAppender complaining that:
> > >         java.sql.SQLException: Cannot create JDBC driver of class ''
> for
> > > connect URL 'null'
> > >
> > > The Appender should write the data to our database at server "foobar",
> > > database "logging-tst". Using the same credentials in SquirrelSQL,
> with
> > > the same JDBC driver, I can connect to that database and query the
> table
> > > specified in the log4j.xml (schema: "logging", table: "usage"; names
> being
> > > case-insensitive).
> > >
> > > Any pointers would be appreciated.
> > >
> > > Environment:
> > > - Centos 7
> > > - Apache Tomcat 8.5.32
> > > - log4j-2.11
> > >
> > > We created a servlet HTTP filter into a JAR, compiled against:
> > > WEB-INF/lib:
> > >         log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
> > >         servlet-api.jar
> > >
> > > This servlet put()'s certain fields into the ThreadContext, which we
> then
> > > attempt to access through %X{...} in the log4j2.xml, appending those
> > > fields as a
> > > row to an existing table in our database.
> > > We had this set-up working previously with log4j-1.something in an MS
> SQL
> > > '05
> > > DB, all on Windows 2003 server (which we are migrating away from due
> to
> > > performance issues).
> > >
> > > Files within the web application:
> > > WEB-INF/lib/
> > >         log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
> > > log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
> > > log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
> > >         postgresql-jdbc.jar
> > >
> > >
> > > META-INF/context.xml:
> > > ---------------------
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <context>
> > >     <resource
> > >         name="jdbc/loggingtst"
> > >         auth="Container"
> > >         type="javax.sql.DataSource"
> > >         username="*****"
> > >         password="*****"
> > >         driverClassName="org.postgresql.Driver"
> > >         url="jdbc:postgresql://foobar:5432/logging-tst"
> > >         maxTotal="20"
> > >         maxIdle="10"
> > >     />
> > > </context>
> > >
> > >
> > > WEB-INF/classes/log4j2.xml:
> > > ---------------------------
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <Configuration status="WARN">
> > >         ...
> > >     <Appenders>
> > >                 ...
> > >         <JDBC name="DBAppender" tableName="logging.usage">
> > >             <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
> > >             <Column name="servername"   pattern="%X{servername}"/>
> > >             <Column name="fex"          pattern="%X{focexec}"/>
> > >             <Column name="parameters"   pattern="%X{parameters}"/>
> > >             <Column name="username"     pattern="%X{username}"/>
> > >             <Column name="duration"     pattern="%X{duration}"/>
> > >             <Column name="user_agent"   pattern="%X{user-agent}"/>
> > >         </JDBC>
> > >     </Appenders>
> > >     <Loggers>
> > >                 ...
> > >         <Logger name="LogFilter" level="info" additivity="false">
> > >             <AppenderRef ref="DBAppender"/>
> > >         </Logger>
> > >
> > >         <Root level="error">
> > >             <AppenderRef ref="sysout" />
> > >         </Root>
> > >     </Loggers>
> > >
> > > </Configuration>
> > >
> > >
> > > WEB-INF/web.xml:
> > > ----------------
> > >   ...
> > >   <resource-ref>
> > >     <description>PostgreSQL logging table</description>
> > >     <res-ref-name>jdbc/loggingtst</res-ref-name>
> > >     <res-type>javax.sql.DataSource</res-type>
> > >     <res-auth>Container</res-auth>
> > >   </resource-ref>
> > >   ...
> > >
> > > With this, catalina.out contains:
> > >
> > > 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
> JdbcDatabaseManager
> > > JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
> > > columnConfigs=[{ name=servername, layout=%X{servername}, literal=null,
> > > timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
> > > timestamp=false }, { name=parameters, layout=%X{parameters},
> literal=null,
> > > timestamp=false }, { name=username, layout=%X{username}, literal=null,
> > > timestamp=false }, { name=duration, layout=%X{duration}, literal=null,
> > > timestamp=false }, { name=user_agent, layout=%X{user-agent},
> literal=null,
> > > timestamp=false }], columnMappings=[]} Could not perform database
> startup
> > > operations: java.sql.SQLException: Cannot create JDBC driver of class
> ''
> > > for connect URL 'null' java.sql.SQLException: Cannot create JDBC
> driver of
> > > class '' for connect URL 'null'
> > >         at
> > >
> > >
> > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> > (BasicDataSource.java:2186)
> > >         at
> > >
> > > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
> > (BasicDataSource.java:2066)
> > >         at
> > >
> > > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
> > (BasicDataSource.java:1525)
> > >         at
> > >
> > >
> >
>
> org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
> > (DataSourceConnectionSource.java:51)
> > >         at
> > >
> > >
> >
>
> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
> > (JdbcDatabaseManager.java:85)
> > >         at
> > >
> > >
> >
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup
> > (AbstractDatabaseManager.java:81)
> > >         at
> > >
> > >
> > org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
> > (AbstractDatabaseAppender.java:106)
> > >         at
> > >
> > > org.apache.logging.log4j.core.config.AbstractConfiguration.start
> > (AbstractConfiguration.java:265)
> > >         at
> > >
> > > org.apache.logging.log4j.core.LoggerContext.setConfiguration
> > (LoggerContext.java:547)
> > >         at
> > >
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
> > >         at
> > >
> > > org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
> > (Log4jContextFactory.java:240)
> > >         at
> > >
> > > org.apache.logging.log4j.core.config.Configurator.initialize
> > (Configurator.java:158)
> > >         at
> > >
> > >
> > org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
> > (Log4jWebInitializerImpl.java:168)
> > >         at
> > >
> > > org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
> > (Log4jWebInitializerImpl.java:110)
> > >         at
> > >
> > >
> > org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
> > (Log4jServletContainerInitializer.java:57)
> > >         at
> > >
> > > org.apache.catalina.core.StandardContext.startInternal
> > (StandardContext.java:5245)
> > >         at
> > > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> > >         at
> > >
> > > org.apache.catalina.core.ContainerBase.addChildInternal
> > (ContainerBase.java:754)
> > >         at
> > >
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
> > >         at
> > > org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
> > >         at
> > >
> > >
>
> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
> > >         at
> > >
> > > org.apache.catalina.startup.HostConfig$DeployDescriptor.run
> > (HostConfig.java:1839)
> > >         at
> > >
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> > >         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> > >         at
> > >
> > > java.util.concurrent.ThreadPoolExecutor.runWorker
> > (ThreadPoolExecutor.java:1149)
> > >         at
> > >
> > > java.util.concurrent.ThreadPoolExecutor$Worker.run
> > (ThreadPoolExecutor.java:624)
> > >         at java.lang.Thread.run(Thread.java:748)
> > > Caused by: java.lang.NullPointerException
> > >         at org.postgresql.Driver.parseURL(Driver.java:551)
> > >         at org.postgresql.Driver.acceptsURL(Driver.java:472)
> > >         at java.sql.DriverManager.getDriver(DriverManager.java:299)
> > >         at
> > >
> > >
> > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> > (BasicDataSource.java:2171)
> > >         ... 26 more
> > >
> > > (Ignore below company statement)
> > >
> > >
> > >
> > > Alban  Hertroys
> > > D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> > > [hidden email]
> > > Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
> The
> > > Netherlands
> > > Chamber of Commerce number: 34223268
> > >
> > >
> > >
> > >
> > > The information contained in this e-mail is intended solely for the
> use of
> > > the
> > > individual or entity to whom it is addressed. If you are not the
> intended
> > > recipient, you are hereby notified that any disclosure, copying,
> > > distribution
> > > or action in relation to the contents of this information is strictly
> > > prohibited and may be unlawful and request you to delete this message
> and
> > > any
> > > attachments and advise the sender by return e-mail. The
> confidentiality of
> > > this
> > > message is not warranted. Apollo Vredestein and its subsidiaries rule
> out
> > > any
> > > and every liability resulting from this or any other electronic
> > > transmission
> > >
> > >
> > >
> > >
> > >
> > >            Please consider the environment before printing this e-mail
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
>
>
> Alban  Hertroys
> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> [hidden email]
> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
> Netherlands
> Chamber of Commerce number: 34223268
>
>
>
>
> The information contained in this e-mail is intended solely for the use of
> the
> individual or entity to whom it is addressed. If you are not the intended
> recipient, you are hereby notified that any disclosure, copying,
> distribution
> or action in relation to the contents of this information is strictly
> prohibited and may be unlawful and request you to delete this message and
> any
> attachments and advise the sender by return e-mail. The confidentiality of
> this
> message is not warranted. Apollo Vredestein and its subsidiaries rule out
> any
> and every liability resulting from this or any other electronic
> transmission
>
>
>
>
>
>            Please consider the environment before printing this e-mail
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> --
Matt Sicker <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: JDBCAppender fails to pass connection URL string

Ralph Goers
I just looked at the JDBC unit tests and surprisingly didn’t see any that use a configuration file.

Ralph

> On Dec 12, 2019, at 7:54 AM, Matt Sicker <[hidden email]> wrote:
>
> Unit tests in the log4j project. All our components have examples in unit
> tests.
>
> On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
> [hidden email]> wrote:
>
>> "Gary Gregory" <[hidden email]> wrote on 2019-12-11 22:01:54:
>>
>>> CAUTION : External email. Do not click links or open  attachments
>>> unless you recognize the sender and know the content is safe.
>>>
>>> AFK, sorry for the top-post. Have you looked at our unit tests? There
>> might
>>> be something there to help see what the usage pattern is for JNDI.
>>
>> You mean to say I should write some Java code to test the JNDI connection
>> as defined in the Tomcat configuration? Or are the unit tests you refer to
>> existing code that is available somewhere?
>>
>> Either way, I have no idea which unit tests you're referring to? I'm also
>> not quite sure what I'm looking for here, I haven't done this before and I
>> don't write Java code on a regular basis. Just created a few snippets to
>> do small stuff here and there, such as this case where we're wrapping a
>> servlet to have some logging of HTTP context information to a database
>> table.
>>
>> There's no requirement here to do the logging through JNDI either; we used
>> a direct connection through log4j.xml previously and that had some issues
>> (mostly losing connection when the DB server got kicked). JNDI just seemed
>> to be the easiest way to set up a connection pool for the JDBCAppender,
>> but now it's starting to look like JNDI is anything but.
>>
>> Regards,
>> Alban.
>>
>>
>>> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
>>> [hidden email]> wrote:
>>>
>>>> Hi,
>>>>
>>>> We're having a lot of trouble getting the JDBCAppender to write to our
>>>> PostgreSQL database. There's probably a configuration error somewhere,
>> but
>>>> we haven't been able to find it. And I have been searching and trying
>> for
>>>> several days now, with no progress at all.
>>>> Even though we specify a connection URL in the JDNI source (see
>> below), it
>>>> always ends with the JDBCAppender complaining that:
>>>>        java.sql.SQLException: Cannot create JDBC driver of class ''
>> for
>>>> connect URL 'null'
>>>>
>>>> The Appender should write the data to our database at server "foobar",
>>>> database "logging-tst". Using the same credentials in SquirrelSQL,
>> with
>>>> the same JDBC driver, I can connect to that database and query the
>> table
>>>> specified in the log4j.xml (schema: "logging", table: "usage"; names
>> being
>>>> case-insensitive).
>>>>
>>>> Any pointers would be appreciated.
>>>>
>>>> Environment:
>>>> - Centos 7
>>>> - Apache Tomcat 8.5.32
>>>> - log4j-2.11
>>>>
>>>> We created a servlet HTTP filter into a JAR, compiled against:
>>>> WEB-INF/lib:
>>>>        log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
>>>>        servlet-api.jar
>>>>
>>>> This servlet put()'s certain fields into the ThreadContext, which we
>> then
>>>> attempt to access through %X{...} in the log4j2.xml, appending those
>>>> fields as a
>>>> row to an existing table in our database.
>>>> We had this set-up working previously with log4j-1.something in an MS
>> SQL
>>>> '05
>>>> DB, all on Windows 2003 server (which we are migrating away from due
>> to
>>>> performance issues).
>>>>
>>>> Files within the web application:
>>>> WEB-INF/lib/
>>>>        log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
>>>> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
>>>> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
>>>>        postgresql-jdbc.jar
>>>>
>>>>
>>>> META-INF/context.xml:
>>>> ---------------------
>>>> <?xml version="1.0" encoding="utf-8"?>
>>>> <context>
>>>>    <resource
>>>>        name="jdbc/loggingtst"
>>>>        auth="Container"
>>>>        type="javax.sql.DataSource"
>>>>        username="*****"
>>>>        password="*****"
>>>>        driverClassName="org.postgresql.Driver"
>>>>        url="jdbc:postgresql://foobar:5432/logging-tst"
>>>>        maxTotal="20"
>>>>        maxIdle="10"
>>>>    />
>>>> </context>
>>>>
>>>>
>>>> WEB-INF/classes/log4j2.xml:
>>>> ---------------------------
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <Configuration status="WARN">
>>>>        ...
>>>>    <Appenders>
>>>>                ...
>>>>        <JDBC name="DBAppender" tableName="logging.usage">
>>>>            <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
>>>>            <Column name="servername"   pattern="%X{servername}"/>
>>>>            <Column name="fex"          pattern="%X{focexec}"/>
>>>>            <Column name="parameters"   pattern="%X{parameters}"/>
>>>>            <Column name="username"     pattern="%X{username}"/>
>>>>            <Column name="duration"     pattern="%X{duration}"/>
>>>>            <Column name="user_agent"   pattern="%X{user-agent}"/>
>>>>        </JDBC>
>>>>    </Appenders>
>>>>    <Loggers>
>>>>                ...
>>>>        <Logger name="LogFilter" level="info" additivity="false">
>>>>            <AppenderRef ref="DBAppender"/>
>>>>        </Logger>
>>>>
>>>>        <Root level="error">
>>>>            <AppenderRef ref="sysout" />
>>>>        </Root>
>>>>    </Loggers>
>>>>
>>>> </Configuration>
>>>>
>>>>
>>>> WEB-INF/web.xml:
>>>> ----------------
>>>>  ...
>>>>  <resource-ref>
>>>>    <description>PostgreSQL logging table</description>
>>>>    <res-ref-name>jdbc/loggingtst</res-ref-name>
>>>>    <res-type>javax.sql.DataSource</res-type>
>>>>    <res-auth>Container</res-auth>
>>>>  </resource-ref>
>>>>  ...
>>>>
>>>> With this, catalina.out contains:
>>>>
>>>> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
>> JdbcDatabaseManager
>>>> JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
>>>> columnConfigs=[{ name=servername, layout=%X{servername}, literal=null,
>>>> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
>>>> timestamp=false }, { name=parameters, layout=%X{parameters},
>> literal=null,
>>>> timestamp=false }, { name=username, layout=%X{username}, literal=null,
>>>> timestamp=false }, { name=duration, layout=%X{duration}, literal=null,
>>>> timestamp=false }, { name=user_agent, layout=%X{user-agent},
>> literal=null,
>>>> timestamp=false }], columnMappings=[]} Could not perform database
>> startup
>>>> operations: java.sql.SQLException: Cannot create JDBC driver of class
>> ''
>>>> for connect URL 'null' java.sql.SQLException: Cannot create JDBC
>> driver of
>>>> class '' for connect URL 'null'
>>>>        at
>>>>
>>>>
>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>>> (BasicDataSource.java:2186)
>>>>        at
>>>>
>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
>>> (BasicDataSource.java:2066)
>>>>        at
>>>>
>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
>>> (BasicDataSource.java:1525)
>>>>        at
>>>>
>>>>
>>>
>>
>> org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
>>> (DataSourceConnectionSource.java:51)
>>>>        at
>>>>
>>>>
>>>
>>
>> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
>>> (JdbcDatabaseManager.java:85)
>>>>        at
>>>>
>>>>
>>>
>> org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup
>>> (AbstractDatabaseManager.java:81)
>>>>        at
>>>>
>>>>
>>> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
>>> (AbstractDatabaseAppender.java:106)
>>>>        at
>>>>
>>>> org.apache.logging.log4j.core.config.AbstractConfiguration.start
>>> (AbstractConfiguration.java:265)
>>>>        at
>>>>
>>>> org.apache.logging.log4j.core.LoggerContext.setConfiguration
>>> (LoggerContext.java:547)
>>>>        at
>>>>
>> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
>>>>        at
>>>>
>>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
>>> (Log4jContextFactory.java:240)
>>>>        at
>>>>
>>>> org.apache.logging.log4j.core.config.Configurator.initialize
>>> (Configurator.java:158)
>>>>        at
>>>>
>>>>
>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
>>> (Log4jWebInitializerImpl.java:168)
>>>>        at
>>>>
>>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
>>> (Log4jWebInitializerImpl.java:110)
>>>>        at
>>>>
>>>>
>>> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
>>> (Log4jServletContainerInitializer.java:57)
>>>>        at
>>>>
>>>> org.apache.catalina.core.StandardContext.startInternal
>>> (StandardContext.java:5245)
>>>>        at
>>>> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>>>>        at
>>>>
>>>> org.apache.catalina.core.ContainerBase.addChildInternal
>>> (ContainerBase.java:754)
>>>>        at
>>>>
>> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
>>>>        at
>>>> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
>>>>        at
>>>>
>>>>
>>
>> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
>>>>        at
>>>>
>>>> org.apache.catalina.startup.HostConfig$DeployDescriptor.run
>>> (HostConfig.java:1839)
>>>>        at
>>>>
>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>>>>        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>>>>        at
>>>>
>>>> java.util.concurrent.ThreadPoolExecutor.runWorker
>>> (ThreadPoolExecutor.java:1149)
>>>>        at
>>>>
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run
>>> (ThreadPoolExecutor.java:624)
>>>>        at java.lang.Thread.run(Thread.java:748)
>>>> Caused by: java.lang.NullPointerException
>>>>        at org.postgresql.Driver.parseURL(Driver.java:551)
>>>>        at org.postgresql.Driver.acceptsURL(Driver.java:472)
>>>>        at java.sql.DriverManager.getDriver(DriverManager.java:299)
>>>>        at
>>>>
>>>>
>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>>> (BasicDataSource.java:2171)
>>>>        ... 26 more
>>>>
>>>> (Ignore below company statement)
>>>>
>>>>
>>>>
>>>> Alban  Hertroys
>>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>>>> [hidden email]
>>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
>> The
>>>> Netherlands
>>>> Chamber of Commerce number: 34223268
>>>>
>>>>
>>>>
>>>>
>>>> The information contained in this e-mail is intended solely for the
>> use of
>>>> the
>>>> individual or entity to whom it is addressed. If you are not the
>> intended
>>>> recipient, you are hereby notified that any disclosure, copying,
>>>> distribution
>>>> or action in relation to the contents of this information is strictly
>>>> prohibited and may be unlawful and request you to delete this message
>> and
>>>> any
>>>> attachments and advise the sender by return e-mail. The
>> confidentiality of
>>>> this
>>>> message is not warranted. Apollo Vredestein and its subsidiaries rule
>> out
>>>> any
>>>> and every liability resulting from this or any other electronic
>>>> transmission
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>           Please consider the environment before printing this e-mail
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>
>>
>> Alban  Hertroys
>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>> [hidden email]
>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
>> Netherlands
>> Chamber of Commerce number: 34223268
>>
>>
>>
>>
>> The information contained in this e-mail is intended solely for the use of
>> the
>> individual or entity to whom it is addressed. If you are not the intended
>> recipient, you are hereby notified that any disclosure, copying,
>> distribution
>> or action in relation to the contents of this information is strictly
>> prohibited and may be unlawful and request you to delete this message and
>> any
>> attachments and advise the sender by return e-mail. The confidentiality of
>> this
>> message is not warranted. Apollo Vredestein and its subsidiaries rule out
>> any
>> and every liability resulting from this or any other electronic
>> transmission
>>
>>
>>
>>
>>
>>           Please consider the environment before printing this e-mail
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>> --
> Matt Sicker <[hidden email]>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: JDBCAppender fails to pass connection URL string

Ralph Goers
http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender <http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender> does have sample configurations but there is not one with the configuration I would expect to use where you can specify the driver class, user name and password.

Ralph

> On Dec 12, 2019, at 7:55 AM, Ralph Goers <[hidden email]> wrote:
>
> I just looked at the JDBC unit tests and surprisingly didn’t see any that use a configuration file.
>
> Ralph
>
>> On Dec 12, 2019, at 7:54 AM, Matt Sicker <[hidden email]> wrote:
>>
>> Unit tests in the log4j project. All our components have examples in unit
>> tests.
>>
>> On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
>> [hidden email]> wrote:
>>
>>> "Gary Gregory" <[hidden email]> wrote on 2019-12-11 22:01:54:
>>>
>>>> CAUTION : External email. Do not click links or open  attachments
>>>> unless you recognize the sender and know the content is safe.
>>>>
>>>> AFK, sorry for the top-post. Have you looked at our unit tests? There
>>> might
>>>> be something there to help see what the usage pattern is for JNDI.
>>>
>>> You mean to say I should write some Java code to test the JNDI connection
>>> as defined in the Tomcat configuration? Or are the unit tests you refer to
>>> existing code that is available somewhere?
>>>
>>> Either way, I have no idea which unit tests you're referring to? I'm also
>>> not quite sure what I'm looking for here, I haven't done this before and I
>>> don't write Java code on a regular basis. Just created a few snippets to
>>> do small stuff here and there, such as this case where we're wrapping a
>>> servlet to have some logging of HTTP context information to a database
>>> table.
>>>
>>> There's no requirement here to do the logging through JNDI either; we used
>>> a direct connection through log4j.xml previously and that had some issues
>>> (mostly losing connection when the DB server got kicked). JNDI just seemed
>>> to be the easiest way to set up a connection pool for the JDBCAppender,
>>> but now it's starting to look like JNDI is anything but.
>>>
>>> Regards,
>>> Alban.
>>>
>>>
>>>> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
>>>> [hidden email]> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> We're having a lot of trouble getting the JDBCAppender to write to our
>>>>> PostgreSQL database. There's probably a configuration error somewhere,
>>> but
>>>>> we haven't been able to find it. And I have been searching and trying
>>> for
>>>>> several days now, with no progress at all.
>>>>> Even though we specify a connection URL in the JDNI source (see
>>> below), it
>>>>> always ends with the JDBCAppender complaining that:
>>>>>       java.sql.SQLException: Cannot create JDBC driver of class ''
>>> for
>>>>> connect URL 'null'
>>>>>
>>>>> The Appender should write the data to our database at server "foobar",
>>>>> database "logging-tst". Using the same credentials in SquirrelSQL,
>>> with
>>>>> the same JDBC driver, I can connect to that database and query the
>>> table
>>>>> specified in the log4j.xml (schema: "logging", table: "usage"; names
>>> being
>>>>> case-insensitive).
>>>>>
>>>>> Any pointers would be appreciated.
>>>>>
>>>>> Environment:
>>>>> - Centos 7
>>>>> - Apache Tomcat 8.5.32
>>>>> - log4j-2.11
>>>>>
>>>>> We created a servlet HTTP filter into a JAR, compiled against:
>>>>> WEB-INF/lib:
>>>>>       log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
>>>>>       servlet-api.jar
>>>>>
>>>>> This servlet put()'s certain fields into the ThreadContext, which we
>>> then
>>>>> attempt to access through %X{...} in the log4j2.xml, appending those
>>>>> fields as a
>>>>> row to an existing table in our database.
>>>>> We had this set-up working previously with log4j-1.something in an MS
>>> SQL
>>>>> '05
>>>>> DB, all on Windows 2003 server (which we are migrating away from due
>>> to
>>>>> performance issues).
>>>>>
>>>>> Files within the web application:
>>>>> WEB-INF/lib/
>>>>>       log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
>>>>> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
>>>>> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
>>>>>       postgresql-jdbc.jar
>>>>>
>>>>>
>>>>> META-INF/context.xml:
>>>>> ---------------------
>>>>> <?xml version="1.0" encoding="utf-8"?>
>>>>> <context>
>>>>>   <resource
>>>>>       name="jdbc/loggingtst"
>>>>>       auth="Container"
>>>>>       type="javax.sql.DataSource"
>>>>>       username="*****"
>>>>>       password="*****"
>>>>>       driverClassName="org.postgresql.Driver"
>>>>>       url="jdbc:postgresql://foobar:5432/logging-tst"
>>>>>       maxTotal="20"
>>>>>       maxIdle="10"
>>>>>   />
>>>>> </context>
>>>>>
>>>>>
>>>>> WEB-INF/classes/log4j2.xml:
>>>>> ---------------------------
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <Configuration status="WARN">
>>>>>       ...
>>>>>   <Appenders>
>>>>>               ...
>>>>>       <JDBC name="DBAppender" tableName="logging.usage">
>>>>>           <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
>>>>>           <Column name="servername"   pattern="%X{servername}"/>
>>>>>           <Column name="fex"          pattern="%X{focexec}"/>
>>>>>           <Column name="parameters"   pattern="%X{parameters}"/>
>>>>>           <Column name="username"     pattern="%X{username}"/>
>>>>>           <Column name="duration"     pattern="%X{duration}"/>
>>>>>           <Column name="user_agent"   pattern="%X{user-agent}"/>
>>>>>       </JDBC>
>>>>>   </Appenders>
>>>>>   <Loggers>
>>>>>               ...
>>>>>       <Logger name="LogFilter" level="info" additivity="false">
>>>>>           <AppenderRef ref="DBAppender"/>
>>>>>       </Logger>
>>>>>
>>>>>       <Root level="error">
>>>>>           <AppenderRef ref="sysout" />
>>>>>       </Root>
>>>>>   </Loggers>
>>>>>
>>>>> </Configuration>
>>>>>
>>>>>
>>>>> WEB-INF/web.xml:
>>>>> ----------------
>>>>> ...
>>>>> <resource-ref>
>>>>>   <description>PostgreSQL logging table</description>
>>>>>   <res-ref-name>jdbc/loggingtst</res-ref-name>
>>>>>   <res-type>javax.sql.DataSource</res-type>
>>>>>   <res-auth>Container</res-auth>
>>>>> </resource-ref>
>>>>> ...
>>>>>
>>>>> With this, catalina.out contains:
>>>>>
>>>>> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
>>> JdbcDatabaseManager
>>>>> JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
>>>>> columnConfigs=[{ name=servername, layout=%X{servername}, literal=null,
>>>>> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
>>>>> timestamp=false }, { name=parameters, layout=%X{parameters},
>>> literal=null,
>>>>> timestamp=false }, { name=username, layout=%X{username}, literal=null,
>>>>> timestamp=false }, { name=duration, layout=%X{duration}, literal=null,
>>>>> timestamp=false }, { name=user_agent, layout=%X{user-agent},
>>> literal=null,
>>>>> timestamp=false }], columnMappings=[]} Could not perform database
>>> startup
>>>>> operations: java.sql.SQLException: Cannot create JDBC driver of class
>>> ''
>>>>> for connect URL 'null' java.sql.SQLException: Cannot create JDBC
>>> driver of
>>>>> class '' for connect URL 'null'
>>>>>       at
>>>>>
>>>>>
>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>>>> (BasicDataSource.java:2186)
>>>>>       at
>>>>>
>>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
>>>> (BasicDataSource.java:2066)
>>>>>       at
>>>>>
>>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
>>>> (BasicDataSource.java:1525)
>>>>>       at
>>>>>
>>>>>
>>>>
>>>
>>> org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
>>>> (DataSourceConnectionSource.java:51)
>>>>>       at
>>>>>
>>>>>
>>>>
>>>
>>> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
>>>> (JdbcDatabaseManager.java:85)
>>>>>       at
>>>>>
>>>>>
>>>>
>>> org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup
>>>> (AbstractDatabaseManager.java:81)
>>>>>       at
>>>>>
>>>>>
>>>> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
>>>> (AbstractDatabaseAppender.java:106)
>>>>>       at
>>>>>
>>>>> org.apache.logging.log4j.core.config.AbstractConfiguration.start
>>>> (AbstractConfiguration.java:265)
>>>>>       at
>>>>>
>>>>> org.apache.logging.log4j.core.LoggerContext.setConfiguration
>>>> (LoggerContext.java:547)
>>>>>       at
>>>>>
>>> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
>>>>>       at
>>>>>
>>>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
>>>> (Log4jContextFactory.java:240)
>>>>>       at
>>>>>
>>>>> org.apache.logging.log4j.core.config.Configurator.initialize
>>>> (Configurator.java:158)
>>>>>       at
>>>>>
>>>>>
>>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
>>>> (Log4jWebInitializerImpl.java:168)
>>>>>       at
>>>>>
>>>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
>>>> (Log4jWebInitializerImpl.java:110)
>>>>>       at
>>>>>
>>>>>
>>>> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
>>>> (Log4jServletContainerInitializer.java:57)
>>>>>       at
>>>>>
>>>>> org.apache.catalina.core.StandardContext.startInternal
>>>> (StandardContext.java:5245)
>>>>>       at
>>>>> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>>>>>       at
>>>>>
>>>>> org.apache.catalina.core.ContainerBase.addChildInternal
>>>> (ContainerBase.java:754)
>>>>>       at
>>>>>
>>> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
>>>>>       at
>>>>> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
>>>>>       at
>>>>>
>>>>>
>>>
>>> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
>>>>>       at
>>>>>
>>>>> org.apache.catalina.startup.HostConfig$DeployDescriptor.run
>>>> (HostConfig.java:1839)
>>>>>       at
>>>>>
>>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>>>>>       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>>>>>       at
>>>>>
>>>>> java.util.concurrent.ThreadPoolExecutor.runWorker
>>>> (ThreadPoolExecutor.java:1149)
>>>>>       at
>>>>>
>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run
>>>> (ThreadPoolExecutor.java:624)
>>>>>       at java.lang.Thread.run(Thread.java:748)
>>>>> Caused by: java.lang.NullPointerException
>>>>>       at org.postgresql.Driver.parseURL(Driver.java:551)
>>>>>       at org.postgresql.Driver.acceptsURL(Driver.java:472)
>>>>>       at java.sql.DriverManager.getDriver(DriverManager.java:299)
>>>>>       at
>>>>>
>>>>>
>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>>>> (BasicDataSource.java:2171)
>>>>>       ... 26 more
>>>>>
>>>>> (Ignore below company statement)
>>>>>
>>>>>
>>>>>
>>>>> Alban  Hertroys
>>>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>>>>> [hidden email]
>>>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
>>> The
>>>>> Netherlands
>>>>> Chamber of Commerce number: 34223268
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> The information contained in this e-mail is intended solely for the
>>> use of
>>>>> the
>>>>> individual or entity to whom it is addressed. If you are not the
>>> intended
>>>>> recipient, you are hereby notified that any disclosure, copying,
>>>>> distribution
>>>>> or action in relation to the contents of this information is strictly
>>>>> prohibited and may be unlawful and request you to delete this message
>>> and
>>>>> any
>>>>> attachments and advise the sender by return e-mail. The
>>> confidentiality of
>>>>> this
>>>>> message is not warranted. Apollo Vredestein and its subsidiaries rule
>>> out
>>>>> any
>>>>> and every liability resulting from this or any other electronic
>>>>> transmission
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          Please consider the environment before printing this e-mail
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>>
>>>
>>>
>>> Alban  Hertroys
>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>>> [hidden email]
>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
>>> Netherlands
>>> Chamber of Commerce number: 34223268
>>>
>>>
>>>
>>>
>>> The information contained in this e-mail is intended solely for the use of
>>> the
>>> individual or entity to whom it is addressed. If you are not the intended
>>> recipient, you are hereby notified that any disclosure, copying,
>>> distribution
>>> or action in relation to the contents of this information is strictly
>>> prohibited and may be unlawful and request you to delete this message and
>>> any
>>> attachments and advise the sender by return e-mail. The confidentiality of
>>> this
>>> message is not warranted. Apollo Vredestein and its subsidiaries rule out
>>> any
>>> and every liability resulting from this or any other electronic
>>> transmission
>>>
>>>
>>>
>>>
>>>
>>>          Please consider the environment before printing this e-mail
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>> --
>> Matt Sicker <[hidden email]>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

Reply | Threaded
Open this post in threaded view
|

Betr: Re: JDBCAppender fails to pass connection URL string

Alban Hertroys
"Ralph Goers" <[hidden email]> wrote on 2019-12-12 16:00:02:

> http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender <
> http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender
> > does have sample configurations but there is not one with the
> configuration I would expect to use where you can specify the driver
> class, user name and password.


...Hang on... Does that mean I'm using a feature from an untested code
path?

I'm created a dumbed down servlet with the same configuration files and it
looks like the context from InitialContext() is empty - that certainly
would explain the null database driver and the empty connection string.



I put the above under Tomcat with a small context-file in
${CATALINA_HOME}/conf/Catalina/localhost and got the output:

        Context contains 0 items.

So it would seem that either my context initialization in de attached Java
class is incorrect, or my context is set up incorrectly somehow.

When adding code to get the DB connection from a DataSource from that
context to that class, I get the same exception as the one I get in my
attempts to set up log4j2. I suspect that the problem is there, but have
no clue where to look.

Is it required to also set up the same JNDI resource in tomcat's
server.xml? I think I tried that, but I removed it as it didn't seem to
help and I don't like having definitions duplicated all over the place.

Regards,
Alban.

> > On Dec 12, 2019, at 7:55 AM, Ralph Goers <[hidden email]>
wrote:
> >
> > I just looked at the JDBC unit tests and surprisingly didn’t see
> any that use a configuration file.
> >
> > Ralph
> >
> >> On Dec 12, 2019, at 7:54 AM, Matt Sicker <[hidden email]> wrote:
> >>
> >> Unit tests in the log4j project. All our components have examples in
unit
> >> tests.
> >>
> >> On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
> >> [hidden email]> wrote:
> >>
> >>> "Gary Gregory" <[hidden email]> wrote on 2019-12-11
22:01:54:
> >>>
> >>>> CAUTION : External email. Do not click links or open  attachments
> >>>> unless you recognize the sender and know the content is safe.
> >>>>
> >>>> AFK, sorry for the top-post. Have you looked at our unit tests?
There
> >>> might
> >>>> be something there to help see what the usage pattern is for JNDI.
> >>>
> >>> You mean to say I should write some Java code to test the JNDI
connection
> >>> as defined in the Tomcat configuration? Or are the unit tests you
refer to
> >>> existing code that is available somewhere?
> >>>
> >>> Either way, I have no idea which unit tests you're referring to? I'm
also
> >>> not quite sure what I'm looking for here, I haven't done this before
and I
> >>> don't write Java code on a regular basis. Just created a few
snippets to
> >>> do small stuff here and there, such as this case where we're
wrapping a
> >>> servlet to have some logging of HTTP context information to a
database
> >>> table.
> >>>
> >>> There's no requirement here to do the logging through JNDI either;
we used
> >>> a direct connection through log4j.xml previously and that had some
issues
> >>> (mostly losing connection when the DB server got kicked). JNDI just
seemed
> >>> to be the easiest way to set up a connection pool for the
JDBCAppender,

> >>> but now it's starting to look like JNDI is anything but.
> >>>
> >>> Regards,
> >>> Alban.
> >>>
> >>>
> >>>> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
> >>>> [hidden email]> wrote:
> >>>>
> >>>>> Hi,
> >>>>>
> >>>>> We're having a lot of trouble getting the JDBCAppender to write to
our
> >>>>> PostgreSQL database. There's probably a configuration error
somewhere,
> >>> but
> >>>>> we haven't been able to find it. And I have been searching and
trying

> >>> for
> >>>>> several days now, with no progress at all.
> >>>>> Even though we specify a connection URL in the JDNI source (see
> >>> below), it
> >>>>> always ends with the JDBCAppender complaining that:
> >>>>>       java.sql.SQLException: Cannot create JDBC driver of class ''
> >>> for
> >>>>> connect URL 'null'
> >>>>>
> >>>>> The Appender should write the data to our database at server
"foobar",
> >>>>> database "logging-tst". Using the same credentials in SquirrelSQL,
> >>> with
> >>>>> the same JDBC driver, I can connect to that database and query the
> >>> table
> >>>>> specified in the log4j.xml (schema: "logging", table: "usage";
names

> >>> being
> >>>>> case-insensitive).
> >>>>>
> >>>>> Any pointers would be appreciated.
> >>>>>
> >>>>> Environment:
> >>>>> - Centos 7
> >>>>> - Apache Tomcat 8.5.32
> >>>>> - log4j-2.11
> >>>>>
> >>>>> We created a servlet HTTP filter into a JAR, compiled against:
> >>>>> WEB-INF/lib:
> >>>>>       log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
> >>>>>       servlet-api.jar
> >>>>>
> >>>>> This servlet put()'s certain fields into the ThreadContext, which
we
> >>> then
> >>>>> attempt to access through %X{...} in the log4j2.xml, appending
those
> >>>>> fields as a
> >>>>> row to an existing table in our database.
> >>>>> We had this set-up working previously with log4j-1.something in an
MS
> >>> SQL
> >>>>> '05
> >>>>> DB, all on Windows 2003 server (which we are migrating away from
due

> >>> to
> >>>>> performance issues).
> >>>>>
> >>>>> Files within the web application:
> >>>>> WEB-INF/lib/
> >>>>>       log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
> >>>>> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
> >>>>> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
> >>>>>       postgresql-jdbc.jar
> >>>>>
> >>>>>
> >>>>> META-INF/context.xml:
> >>>>> ---------------------
> >>>>> <?xml version="1.0" encoding="utf-8"?>
> >>>>> <context>
> >>>>>   <resource
> >>>>>       name="jdbc/loggingtst"
> >>>>>       auth="Container"
> >>>>>       type="javax.sql.DataSource"
> >>>>>       username="*****"
> >>>>>       password="*****"
> >>>>>       driverClassName="org.postgresql.Driver"
> >>>>>       url="jdbc:postgresql://foobar:5432/logging-tst"
> >>>>>       maxTotal="20"
> >>>>>       maxIdle="10"
> >>>>>   />
> >>>>> </context>
> >>>>>
> >>>>>
> >>>>> WEB-INF/classes/log4j2.xml:
> >>>>> ---------------------------
> >>>>> <?xml version="1.0" encoding="UTF-8"?>
> >>>>> <Configuration status="WARN">
> >>>>>       ...
> >>>>>   <Appenders>
> >>>>>               ...
> >>>>>       <JDBC name="DBAppender" tableName="logging.usage">
> >>>>>           <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
> >>>>>           <Column name="servername"   pattern="%X{servername}"/>
> >>>>>           <Column name="fex"          pattern="%X{focexec}"/>
> >>>>>           <Column name="parameters"   pattern="%X{parameters}"/>
> >>>>>           <Column name="username"     pattern="%X{username}"/>
> >>>>>           <Column name="duration"     pattern="%X{duration}"/>
> >>>>>           <Column name="user_agent"   pattern="%X{user-agent}"/>
> >>>>>       </JDBC>
> >>>>>   </Appenders>
> >>>>>   <Loggers>
> >>>>>               ...
> >>>>>       <Logger name="LogFilter" level="info" additivity="false">
> >>>>>           <AppenderRef ref="DBAppender"/>
> >>>>>       </Logger>
> >>>>>
> >>>>>       <Root level="error">
> >>>>>           <AppenderRef ref="sysout" />
> >>>>>       </Root>
> >>>>>   </Loggers>
> >>>>>
> >>>>> </Configuration>
> >>>>>
> >>>>>
> >>>>> WEB-INF/web.xml:
> >>>>> ----------------
> >>>>> ...
> >>>>> <resource-ref>
> >>>>>   <description>PostgreSQL logging table</description>
> >>>>>   <res-ref-name>jdbc/loggingtst</res-ref-name>
> >>>>>   <res-type>javax.sql.DataSource</res-type>
> >>>>>   <res-auth>Container</res-auth>
> >>>>> </resource-ref>
> >>>>> ...
> >>>>>
> >>>>> With this, catalina.out contains:
> >>>>>
> >>>>> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
> >>> JdbcDatabaseManager
> >>>>> JdbcManager{name=FexAppender, bufferSize=0,
tableName=logging.usage,
> >>>>> columnConfigs=[{ name=servername, layout=%X{servername},
literal=null,
> >>>>> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
> >>>>> timestamp=false }, { name=parameters, layout=%X{parameters},
> >>> literal=null,
> >>>>> timestamp=false }, { name=username, layout=%X{username},
literal=null,
> >>>>> timestamp=false }, { name=duration, layout=%X{duration},
literal=null,
> >>>>> timestamp=false }, { name=user_agent, layout=%X{user-agent},
> >>> literal=null,
> >>>>> timestamp=false }], columnMappings=[]} Could not perform database
> >>> startup
> >>>>> operations: java.sql.SQLException: Cannot create JDBC driver of
class
> >>> ''
> >>>>> for connect URL 'null' java.sql.SQLException: Cannot create JDBC
> >>> driver of
> >>>>> class '' for connect URL 'null'
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory

> >>>> (BasicDataSource.java:2186)
> >>>>>       at
> >>>>>
> >>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
> >>>> (BasicDataSource.java:2066)
> >>>>>       at
> >>>>>
> >>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
> >>>> (BasicDataSource.java:1525)
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
> >>>
> >>>
>
org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
> >>>> (DataSourceConnectionSource.java:51)
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
> >>>
> >>>
>
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
> >>>> (JdbcDatabaseManager.java:85)
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
> >>>
org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup
> >>>> (AbstractDatabaseManager.java:81)
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start

> >>>> (AbstractDatabaseAppender.java:106)
> >>>>>       at
> >>>>>
> >>>>> org.apache.logging.log4j.core.config.AbstractConfiguration.start
> >>>> (AbstractConfiguration.java:265)
> >>>>>       at
> >>>>>
> >>>>> org.apache.logging.log4j.core.LoggerContext.setConfiguration
> >>>> (LoggerContext.java:547)
> >>>>>       at
> >>>>>
> >>>
org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)

> >>>>>       at
> >>>>>
> >>>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
> >>>> (Log4jContextFactory.java:240)
> >>>>>       at
> >>>>>
> >>>>> org.apache.logging.log4j.core.config.Configurator.initialize
> >>>> (Configurator.java:158)
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
> >>>> (Log4jWebInitializerImpl.java:168)
> >>>>>       at
> >>>>>
> >>>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
> >>>> (Log4jWebInitializerImpl.java:110)
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
> >>>> (Log4jServletContainerInitializer.java:57)
> >>>>>       at
> >>>>>
> >>>>> org.apache.catalina.core.StandardContext.startInternal
> >>>> (StandardContext.java:5245)
> >>>>>       at
> >>>>>
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >>>>>       at
> >>>>>
> >>>>> org.apache.catalina.core.ContainerBase.addChildInternal
> >>>> (ContainerBase.java:754)
> >>>>>       at
> >>>>>
> >>>
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
> >>>>>       at
> >>>>>
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)

> >>>>>       at
> >>>>>
> >>>>>
> >>>
> >>> org.apache.catalina.startup.HostConfig.deployDescriptor
> (HostConfig.java:629)
> >>>>>       at
> >>>>>
> >>>>> org.apache.catalina.startup.HostConfig$DeployDescriptor.run
> >>>> (HostConfig.java:1839)
> >>>>>       at
> >>>>>
> >>>
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

> >>>>>       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> >>>>>       at
> >>>>>
> >>>>> java.util.concurrent.ThreadPoolExecutor.runWorker
> >>>> (ThreadPoolExecutor.java:1149)
> >>>>>       at
> >>>>>
> >>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run
> >>>> (ThreadPoolExecutor.java:624)
> >>>>>       at java.lang.Thread.run(Thread.java:748)
> >>>>> Caused by: java.lang.NullPointerException
> >>>>>       at org.postgresql.Driver.parseURL(Driver.java:551)
> >>>>>       at org.postgresql.Driver.acceptsURL(Driver.java:472)
> >>>>>       at java.sql.DriverManager.getDriver(DriverManager.java:299)
> >>>>>       at
> >>>>>
> >>>>>
> >>>>
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory

> >>>> (BasicDataSource.java:2171)
> >>>>>       ... 26 more
> >>>>>
> >>>>> (Ignore below company statement)
> >>>>>
> >>>>>
> >>>>>
> >>>>> Alban  Hertroys
> >>>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> >>>>> [hidden email]
> >>>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD
Enschede,
> >>> The
> >>>>> Netherlands
> >>>>> Chamber of Commerce number: 34223268
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> The information contained in this e-mail is intended solely for
the
> >>> use of
> >>>>> the
> >>>>> individual or entity to whom it is addressed. If you are not the
> >>> intended
> >>>>> recipient, you are hereby notified that any disclosure, copying,
> >>>>> distribution
> >>>>> or action in relation to the contents of this information is
strictly
> >>>>> prohibited and may be unlawful and request you to delete this
message
> >>> and
> >>>>> any
> >>>>> attachments and advise the sender by return e-mail. The
> >>> confidentiality of
> >>>>> this
> >>>>> message is not warranted. Apollo Vredestein and its subsidiaries
rule

> >>> out
> >>>>> any
> >>>>> and every liability resulting from this or any other electronic
> >>>>> transmission
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>          Please consider the environment before printing this
e-mail
> >>>>>
> >>>>>
> >>>>>
---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: [hidden email]
> >>>>> For additional commands, e-mail:
[hidden email]
> >>>>>
> >>>>>
> >>>
> >>>
> >>> Alban  Hertroys
> >>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> >>> [hidden email]
> >>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD
Enschede, The
> >>> Netherlands
> >>> Chamber of Commerce number: 34223268
> >>>
> >>>
> >>>
> >>>
> >>> The information contained in this e-mail is intended solely for the
use of
> >>> the
> >>> individual or entity to whom it is addressed. If you are not the
intended
> >>> recipient, you are hereby notified that any disclosure, copying,
> >>> distribution
> >>> or action in relation to the contents of this information is
strictly
> >>> prohibited and may be unlawful and request you to delete this
message and
> >>> any
> >>> attachments and advise the sender by return e-mail. The
confidentiality of
> >>> this
> >>> message is not warranted. Apollo Vredestein and its subsidiaries
rule out

> >>> any
> >>> and every liability resulting from this or any other electronic
> >>> transmission
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>          Please consider the environment before printing this e-mail
> >>>
> >>>
> >>>
---------------------------------------------------------------------

> >>> To unsubscribe, e-mail: [hidden email]
> >>> For additional commands, e-mail: [hidden email]
> >>>
> >>> --
> >> Matt Sicker <[hidden email]>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>

Alban  Hertroys    
D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E: [hidden email]
Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
Netherlands
Chamber of Commerce number: 34223268

 
       
                 
The information contained in this e-mail is intended solely for the use of the
individual or entity to whom it is addressed. If you are not the intended
recipient, you are hereby notified that any disclosure, copying, distribution
or action in relation to the contents of this information is strictly
prohibited and may be unlawful and request you to delete this message and any
attachments and advise the sender by return e-mail. The confidentiality of this
message is not warranted. Apollo Vredestein and its subsidiaries rule out any
and every liability resulting from this or any other electronic transmission



       
               
           Please consider the environment before printing this e-mail


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Betr: Betr: Re: JDBCAppender fails to pass connection URL string

Alban Hertroys
Rats, the attachment got stripped. Here's the code:

/* vim: ts=4 sw=4 cindent
 */
import java.io.IOException;
import java.io.PrintWriter;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NameClassPair;
import javax.naming.NamingException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/DataSourceExample")
public class DataSourceExample extends HttpServlet
{
        private static final long serialVersionUID = 1L;

        protected void doGet(
                        HttpServletRequest      request
                ,       HttpServletResponse     response
        )
        throws ServletException, IOException
        {
                Context ctx = null;

                try {
                        PrintWriter out = response.getWriter();
                        response.setContentType("text/plain");

                        ctx = new InitialContext();

                        try {
                                printCtx(ctx, out);
                        }
                        catch (NamingException e) {
                                out.println(e);
                        }
                }
                catch (NamingException e)       { e.printStackTrace(); }
                finally {
                        try {
                                ctx.close();
                        }
                        catch (NamingException e) {
System.out.println("Exception in closing context."); }
                }
        }

        private void printCtx(Context ctx, PrintWriter out)
        throws NamingException
        {
                NamingEnumeration<NameClassPair> list = ctx.list("");
                int rows = 0;

                for (;list.hasMore(); rows++) {
                        NameClassPair pair = list.next();
                        out.print(pair.getName() + " : ");
                        try {
                                out.print(ctx.lookup(pair.getName()));
                        }
                        catch (Exception e) {}
                        out.println("");
                }

                out.println("Context contains " + rows + " items.");
        }
}

"Alban Hertroys" <[hidden email]> wrote on 2019-12-12
17:20:26:

> Van: "Alban Hertroys" <[hidden email]>
> Aan: "Log4J Users List" <[hidden email]>
> Datum: 2019-12-12 17:20
> Onderwerp: Betr: Re: JDBCAppender fails to pass connection URL string
>
> CAUTION : External email. Do not click links or open  attachments
> unless you recognize the sender and know the content is safe.
>
> "Ralph Goers" <[hidden email]> wrote on 2019-12-12 16:00:02:
>
> > http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender 
<

> > http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender
> > > does have sample configurations but there is not one with the
> > configuration I would expect to use where you can specify the driver
> > class, user name and password.
>
>
> ...Hang on... Does that mean I'm using a feature from an untested code
> path?
>
> I'm created a dumbed down servlet with the same configuration files and
it

> looks like the context from InitialContext() is empty - that certainly
> would explain the null database driver and the empty connection string.
>
>
>
> I put the above under Tomcat with a small context-file in
> ${CATALINA_HOME}/conf/Catalina/localhost and got the output:
>
>         Context contains 0 items.
>
> So it would seem that either my context initialization in de attached
Java
> class is incorrect, or my context is set up incorrectly somehow.
>
> When adding code to get the DB connection from a DataSource from that
> context to that class, I get the same exception as the one I get in my
> attempts to set up log4j2. I suspect that the problem is there, but have

> no clue where to look.
>
> Is it required to also set up the same JNDI resource in tomcat's
> server.xml? I think I tried that, but I removed it as it didn't seem to
> help and I don't like having definitions duplicated all over the place.
>
> Regards,
> Alban.
>
> > > On Dec 12, 2019, at 7:55 AM, Ralph Goers
<[hidden email]>

> wrote:
> > >
> > > I just looked at the JDBC unit tests and surprisingly didn’t see
> > any that use a configuration file.
> > >
> > > Ralph
> > >
> > >> On Dec 12, 2019, at 7:54 AM, Matt Sicker <[hidden email]> wrote:
> > >>
> > >> Unit tests in the log4j project. All our components have examples
in

> unit
> > >> tests.
> > >>
> > >> On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
> > >> [hidden email]> wrote:
> > >>
> > >>> "Gary Gregory" <[hidden email]> wrote on 2019-12-11
> 22:01:54:
> > >>>
> > >>>> CAUTION : External email. Do not click links or open  attachments
> > >>>> unless you recognize the sender and know the content is safe.
> > >>>>
> > >>>> AFK, sorry for the top-post. Have you looked at our unit tests?
> There
> > >>> might
> > >>>> be something there to help see what the usage pattern is for
JNDI.
> > >>>
> > >>> You mean to say I should write some Java code to test the JNDI
> connection
> > >>> as defined in the Tomcat configuration? Or are the unit tests you
> refer to
> > >>> existing code that is available somewhere?
> > >>>
> > >>> Either way, I have no idea which unit tests you're referring to?
I'm
> also
> > >>> not quite sure what I'm looking for here, I haven't done this
before

> and I
> > >>> don't write Java code on a regular basis. Just created a few
> snippets to
> > >>> do small stuff here and there, such as this case where we're
> wrapping a
> > >>> servlet to have some logging of HTTP context information to a
> database
> > >>> table.
> > >>>
> > >>> There's no requirement here to do the logging through JNDI either;

> we used
> > >>> a direct connection through log4j.xml previously and that had some

> issues
> > >>> (mostly losing connection when the DB server got kicked). JNDI
just

> seemed
> > >>> to be the easiest way to set up a connection pool for the
> JDBCAppender,
> > >>> but now it's starting to look like JNDI is anything but.
> > >>>
> > >>> Regards,
> > >>> Alban.
> > >>>
> > >>>
> > >>>> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
> > >>>> [hidden email]> wrote:
> > >>>>
> > >>>>> Hi,
> > >>>>>
> > >>>>> We're having a lot of trouble getting the JDBCAppender to write
to

> our
> > >>>>> PostgreSQL database. There's probably a configuration error
> somewhere,
> > >>> but
> > >>>>> we haven't been able to find it. And I have been searching and
> trying
> > >>> for
> > >>>>> several days now, with no progress at all.
> > >>>>> Even though we specify a connection URL in the JDNI source (see
> > >>> below), it
> > >>>>> always ends with the JDBCAppender complaining that:
> > >>>>>       java.sql.SQLException: Cannot create JDBC driver of class
''
> > >>> for
> > >>>>> connect URL 'null'
> > >>>>>
> > >>>>> The Appender should write the data to our database at server
> "foobar",
> > >>>>> database "logging-tst". Using the same credentials in
SquirrelSQL,
> > >>> with
> > >>>>> the same JDBC driver, I can connect to that database and query
the

> > >>> table
> > >>>>> specified in the log4j.xml (schema: "logging", table: "usage";
> names
> > >>> being
> > >>>>> case-insensitive).
> > >>>>>
> > >>>>> Any pointers would be appreciated.
> > >>>>>
> > >>>>> Environment:
> > >>>>> - Centos 7
> > >>>>> - Apache Tomcat 8.5.32
> > >>>>> - log4j-2.11
> > >>>>>
> > >>>>> We created a servlet HTTP filter into a JAR, compiled against:
> > >>>>> WEB-INF/lib:
> > >>>>>       log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
> > >>>>>       servlet-api.jar
> > >>>>>
> > >>>>> This servlet put()'s certain fields into the ThreadContext,
which
> we
> > >>> then
> > >>>>> attempt to access through %X{...} in the log4j2.xml, appending
> those
> > >>>>> fields as a
> > >>>>> row to an existing table in our database.
> > >>>>> We had this set-up working previously with log4j-1.something in
an
> MS
> > >>> SQL
> > >>>>> '05
> > >>>>> DB, all on Windows 2003 server (which we are migrating away from

> due
> > >>> to
> > >>>>> performance issues).
> > >>>>>
> > >>>>> Files within the web application:
> > >>>>> WEB-INF/lib/
> > >>>>>       log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
> > >>>>> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar log4j-jul-2.11.0.jar
> > >>>>> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
> > >>>>>       postgresql-jdbc.jar
> > >>>>>
> > >>>>>
> > >>>>> META-INF/context.xml:
> > >>>>> ---------------------
> > >>>>> <?xml version="1.0" encoding="utf-8"?>
> > >>>>> <context>
> > >>>>>   <resource
> > >>>>>       name="jdbc/loggingtst"
> > >>>>>       auth="Container"
> > >>>>>       type="javax.sql.DataSource"
> > >>>>>       username="*****"
> > >>>>>       password="*****"
> > >>>>>       driverClassName="org.postgresql.Driver"
> > >>>>>       url="jdbc:postgresql://foobar:5432/logging-tst"
> > >>>>>       maxTotal="20"
> > >>>>>       maxIdle="10"
> > >>>>>   />
> > >>>>> </context>
> > >>>>>
> > >>>>>
> > >>>>> WEB-INF/classes/log4j2.xml:
> > >>>>> ---------------------------
> > >>>>> <?xml version="1.0" encoding="UTF-8"?>
> > >>>>> <Configuration status="WARN">
> > >>>>>       ...
> > >>>>>   <Appenders>
> > >>>>>               ...
> > >>>>>       <JDBC name="DBAppender" tableName="logging.usage">
> > >>>>>           <DataSource
jndiName="java:/comp/env/jdbc/loggingtst"/>

> > >>>>>           <Column name="servername"   pattern="%X{servername}"/>
> > >>>>>           <Column name="fex"          pattern="%X{focexec}"/>
> > >>>>>           <Column name="parameters"   pattern="%X{parameters}"/>
> > >>>>>           <Column name="username"     pattern="%X{username}"/>
> > >>>>>           <Column name="duration"     pattern="%X{duration}"/>
> > >>>>>           <Column name="user_agent"   pattern="%X{user-agent}"/>
> > >>>>>       </JDBC>
> > >>>>>   </Appenders>
> > >>>>>   <Loggers>
> > >>>>>               ...
> > >>>>>       <Logger name="LogFilter" level="info" additivity="false">
> > >>>>>           <AppenderRef ref="DBAppender"/>
> > >>>>>       </Logger>
> > >>>>>
> > >>>>>       <Root level="error">
> > >>>>>           <AppenderRef ref="sysout" />
> > >>>>>       </Root>
> > >>>>>   </Loggers>
> > >>>>>
> > >>>>> </Configuration>
> > >>>>>
> > >>>>>
> > >>>>> WEB-INF/web.xml:
> > >>>>> ----------------
> > >>>>> ...
> > >>>>> <resource-ref>
> > >>>>>   <description>PostgreSQL logging table</description>
> > >>>>>   <res-ref-name>jdbc/loggingtst</res-ref-name>
> > >>>>>   <res-type>javax.sql.DataSource</res-type>
> > >>>>>   <res-auth>Container</res-auth>
> > >>>>> </resource-ref>
> > >>>>> ...
> > >>>>>
> > >>>>> With this, catalina.out contains:
> > >>>>>
> > >>>>> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
> > >>> JdbcDatabaseManager
> > >>>>> JdbcManager{name=FexAppender, bufferSize=0,
> tableName=logging.usage,
> > >>>>> columnConfigs=[{ name=servername, layout=%X{servername},
> literal=null,
> > >>>>> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
> > >>>>> timestamp=false }, { name=parameters, layout=%X{parameters},
> > >>> literal=null,
> > >>>>> timestamp=false }, { name=username, layout=%X{username},
> literal=null,
> > >>>>> timestamp=false }, { name=duration, layout=%X{duration},
> literal=null,
> > >>>>> timestamp=false }, { name=user_agent, layout=%X{user-agent},
> > >>> literal=null,
> > >>>>> timestamp=false }], columnMappings=[]} Could not perform
database

> > >>> startup
> > >>>>> operations: java.sql.SQLException: Cannot create JDBC driver of
> class
> > >>> ''
> > >>>>> for connect URL 'null' java.sql.SQLException: Cannot create JDBC
> > >>> driver of
> > >>>>> class '' for connect URL 'null'
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> > >>>> (BasicDataSource.java:2186)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
> > >>>> (BasicDataSource.java:2066)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
> > >>>> (BasicDataSource.java:1525)
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> > >>>
> > >>>
> >
>
org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
> > >>>> (DataSourceConnectionSource.java:51)
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> > >>>
> > >>>
> >
>
org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
> > >>>> (JdbcDatabaseManager.java:85)
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> > >>>
>
org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup

> > >>>> (AbstractDatabaseManager.java:81)
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
> > >>>> (AbstractDatabaseAppender.java:106)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.logging.log4j.core.config.AbstractConfiguration.start
> > >>>> (AbstractConfiguration.java:265)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.logging.log4j.core.LoggerContext.setConfiguration
> > >>>> (LoggerContext.java:547)
> > >>>>>       at
> > >>>>>
> > >>>
>
org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
> > >>>>>       at
> > >>>>>
> > >>>>>
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext

> > >>>> (Log4jContextFactory.java:240)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.logging.log4j.core.config.Configurator.initialize
> > >>>> (Configurator.java:158)
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
> > >>>> (Log4jWebInitializerImpl.java:168)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
> > >>>> (Log4jWebInitializerImpl.java:110)
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
> > >>>> (Log4jServletContainerInitializer.java:57)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.catalina.core.StandardContext.startInternal
> > >>>> (StandardContext.java:5245)
> > >>>>>       at
> > >>>>>
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.catalina.core.ContainerBase.addChildInternal
> > >>>> (ContainerBase.java:754)
> > >>>>>       at
> > >>>>>
> > >>>
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
> > >>>>>       at
> > >>>>>
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>
> > >>> org.apache.catalina.startup.HostConfig.deployDescriptor
> > (HostConfig.java:629)
> > >>>>>       at
> > >>>>>
> > >>>>> org.apache.catalina.startup.HostConfig$DeployDescriptor.run
> > >>>> (HostConfig.java:1839)
> > >>>>>       at
> > >>>>>
> > >>>
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> > >>>>>       at
java.util.concurrent.FutureTask.run(FutureTask.java:266)

> > >>>>>       at
> > >>>>>
> > >>>>> java.util.concurrent.ThreadPoolExecutor.runWorker
> > >>>> (ThreadPoolExecutor.java:1149)
> > >>>>>       at
> > >>>>>
> > >>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run
> > >>>> (ThreadPoolExecutor.java:624)
> > >>>>>       at java.lang.Thread.run(Thread.java:748)
> > >>>>> Caused by: java.lang.NullPointerException
> > >>>>>       at org.postgresql.Driver.parseURL(Driver.java:551)
> > >>>>>       at org.postgresql.Driver.acceptsURL(Driver.java:472)
> > >>>>>       at
java.sql.DriverManager.getDriver(DriverManager.java:299)

> > >>>>>       at
> > >>>>>
> > >>>>>
> > >>>>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> > >>>> (BasicDataSource.java:2171)
> > >>>>>       ... 26 more
> > >>>>>
> > >>>>> (Ignore below company statement)
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>> Alban  Hertroys
> > >>>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> > >>>>> [hidden email]
> > >>>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD
> Enschede,
> > >>> The
> > >>>>> Netherlands
> > >>>>> Chamber of Commerce number: 34223268
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>> The information contained in this e-mail is intended solely for
> the
> > >>> use of
> > >>>>> the
> > >>>>> individual or entity to whom it is addressed. If you are not the
> > >>> intended
> > >>>>> recipient, you are hereby notified that any disclosure, copying,
> > >>>>> distribution
> > >>>>> or action in relation to the contents of this information is
> strictly
> > >>>>> prohibited and may be unlawful and request you to delete this
> message
> > >>> and
> > >>>>> any
> > >>>>> attachments and advise the sender by return e-mail. The
> > >>> confidentiality of
> > >>>>> this
> > >>>>> message is not warranted. Apollo Vredestein and its subsidiaries

> rule
> > >>> out
> > >>>>> any
> > >>>>> and every liability resulting from this or any other electronic
> > >>>>> transmission
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>          Please consider the environment before printing this
> e-mail
> > >>>>>
> > >>>>>
> > >>>>>
> ---------------------------------------------------------------------
> > >>>>> To unsubscribe, e-mail:
[hidden email]

> > >>>>> For additional commands, e-mail:
> [hidden email]
> > >>>>>
> > >>>>>
> > >>>
> > >>>
> > >>> Alban  Hertroys
> > >>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> > >>> [hidden email]
> > >>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD
> Enschede, The
> > >>> Netherlands
> > >>> Chamber of Commerce number: 34223268
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> The information contained in this e-mail is intended solely for
the

> use of
> > >>> the
> > >>> individual or entity to whom it is addressed. If you are not the
> intended
> > >>> recipient, you are hereby notified that any disclosure, copying,
> > >>> distribution
> > >>> or action in relation to the contents of this information is
> strictly
> > >>> prohibited and may be unlawful and request you to delete this
> message and
> > >>> any
> > >>> attachments and advise the sender by return e-mail. The
> confidentiality of
> > >>> this
> > >>> message is not warranted. Apollo Vredestein and its subsidiaries
> rule out
> > >>> any
> > >>> and every liability resulting from this or any other electronic
> > >>> transmission
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>          Please consider the environment before printing this
e-mail
> > >>>
> > >>>
> > >>>
> ---------------------------------------------------------------------
> > >>> To unsubscribe, e-mail: [hidden email]
> > >>> For additional commands, e-mail:
[hidden email]
> > >>>
> > >>> --
> > >> Matt Sicker <[hidden email]>
> > >
> > >
> > >
> > >
---------------------------------------------------------------------

> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
>
>
> Alban  Hertroys
> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> [hidden email]
> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
The
> Netherlands
> Chamber of Commerce number: 34223268
>
>
>
>
> The information contained in this e-mail is intended solely for the
> use of the
> individual or entity to whom it is addressed. If you are not the
intended
> recipient, you are hereby notified that any disclosure, copying,
distribution
> or action in relation to the contents of this information is strictly
> prohibited and may be unlawful and request you to delete this message
and any
> attachments and advise the sender by return e-mail. The
> confidentiality of this
> message is not warranted. Apollo Vredestein and its subsidiaries rule
out any
> and every liability resulting from this or any other electronic
transmission

>
>
>
>
>
>       Please consider the environment before printing this e-mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]

Alban  Hertroys    
D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E: [hidden email]
Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
Netherlands
Chamber of Commerce number: 34223268

 
       
                 
The information contained in this e-mail is intended solely for the use of the
individual or entity to whom it is addressed. If you are not the intended
recipient, you are hereby notified that any disclosure, copying, distribution
or action in relation to the contents of this information is strictly
prohibited and may be unlawful and request you to delete this message and any
attachments and advise the sender by return e-mail. The confidentiality of this
message is not warranted. Apollo Vredestein and its subsidiaries rule out any
and every liability resulting from this or any other electronic transmission



       
               
           Please consider the environment before printing this e-mail

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Betr: Re: JDBCAppender fails to pass connection URL string

Ralph Goers
In reply to this post by Alban Hertroys
No, it doesn’t necessarily mean that.  Some of the unit tests configure things programmatically by directly calling the plugins.

If you look at the documentation you will see <DriverManager> and <PoolingDriver> as connection sources you can configure. You should try that. I don’t know why examples weren’t added to the doc of how to use them but they should be straightforward.

Ralph

> On Dec 12, 2019, at 9:20 AM, Alban Hertroys <[hidden email]> wrote:
>
> "Ralph Goers" <[hidden email]> wrote on 2019-12-12 16:00:02:
>
>> http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender <
>> http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender
>>> does have sample configurations but there is not one with the
>> configuration I would expect to use where you can specify the driver
>> class, user name and password.
>
>
> ...Hang on... Does that mean I'm using a feature from an untested code
> path?
>
> I'm created a dumbed down servlet with the same configuration files and it
> looks like the context from InitialContext() is empty - that certainly
> would explain the null database driver and the empty connection string.
>
>
>
> I put the above under Tomcat with a small context-file in
> ${CATALINA_HOME}/conf/Catalina/localhost and got the output:
>
>        Context contains 0 items.
>
> So it would seem that either my context initialization in de attached Java
> class is incorrect, or my context is set up incorrectly somehow.
>
> When adding code to get the DB connection from a DataSource from that
> context to that class, I get the same exception as the one I get in my
> attempts to set up log4j2. I suspect that the problem is there, but have
> no clue where to look.
>
> Is it required to also set up the same JNDI resource in tomcat's
> server.xml? I think I tried that, but I removed it as it didn't seem to
> help and I don't like having definitions duplicated all over the place.
>
> Regards,
> Alban.
>
>>> On Dec 12, 2019, at 7:55 AM, Ralph Goers <[hidden email]>
> wrote:
>>>
>>> I just looked at the JDBC unit tests and surprisingly didn’t see
>> any that use a configuration file.
>>>
>>> Ralph
>>>
>>>> On Dec 12, 2019, at 7:54 AM, Matt Sicker <[hidden email]> wrote:
>>>>
>>>> Unit tests in the log4j project. All our components have examples in
> unit
>>>> tests.
>>>>
>>>> On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
>>>> [hidden email]> wrote:
>>>>
>>>>> "Gary Gregory" <[hidden email]> wrote on 2019-12-11
> 22:01:54:
>>>>>
>>>>>> CAUTION : External email. Do not click links or open  attachments
>>>>>> unless you recognize the sender and know the content is safe.
>>>>>>
>>>>>> AFK, sorry for the top-post. Have you looked at our unit tests?
> There
>>>>> might
>>>>>> be something there to help see what the usage pattern is for JNDI.
>>>>>
>>>>> You mean to say I should write some Java code to test the JNDI
> connection
>>>>> as defined in the Tomcat configuration? Or are the unit tests you
> refer to
>>>>> existing code that is available somewhere?
>>>>>
>>>>> Either way, I have no idea which unit tests you're referring to? I'm
> also
>>>>> not quite sure what I'm looking for here, I haven't done this before
> and I
>>>>> don't write Java code on a regular basis. Just created a few
> snippets to
>>>>> do small stuff here and there, such as this case where we're
> wrapping a
>>>>> servlet to have some logging of HTTP context information to a
> database
>>>>> table.
>>>>>
>>>>> There's no requirement here to do the logging through JNDI either;
> we used
>>>>> a direct connection through log4j.xml previously and that had some
> issues
>>>>> (mostly losing connection when the DB server got kicked). JNDI just
> seemed
>>>>> to be the easiest way to set up a connection pool for the
> JDBCAppender,
>>>>> but now it's starting to look like JNDI is anything but.
>>>>>
>>>>> Regards,
>>>>> Alban.
>>>>>
>>>>>
>>>>>> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
>>>>>> [hidden email]> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> We're having a lot of trouble getting the JDBCAppender to write to
> our
>>>>>>> PostgreSQL database. There's probably a configuration error
> somewhere,
>>>>> but
>>>>>>> we haven't been able to find it. And I have been searching and
> trying
>>>>> for
>>>>>>> several days now, with no progress at all.
>>>>>>> Even though we specify a connection URL in the JDNI source (see
>>>>> below), it
>>>>>>> always ends with the JDBCAppender complaining that:
>>>>>>>      java.sql.SQLException: Cannot create JDBC driver of class ''
>>>>> for
>>>>>>> connect URL 'null'
>>>>>>>
>>>>>>> The Appender should write the data to our database at server
> "foobar",
>>>>>>> database "logging-tst". Using the same credentials in SquirrelSQL,
>>>>> with
>>>>>>> the same JDBC driver, I can connect to that database and query the
>>>>> table
>>>>>>> specified in the log4j.xml (schema: "logging", table: "usage";
> names
>>>>> being
>>>>>>> case-insensitive).
>>>>>>>
>>>>>>> Any pointers would be appreciated.
>>>>>>>
>>>>>>> Environment:
>>>>>>> - Centos 7
>>>>>>> - Apache Tomcat 8.5.32
>>>>>>> - log4j-2.11
>>>>>>>
>>>>>>> We created a servlet HTTP filter into a JAR, compiled against:
>>>>>>> WEB-INF/lib:
>>>>>>>      log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
>>>>>>>      servlet-api.jar
>>>>>>>
>>>>>>> This servlet put()'s certain fields into the ThreadContext, which
> we
>>>>> then
>>>>>>> attempt to access through %X{...} in the log4j2.xml, appending
> those
>>>>>>> fields as a
>>>>>>> row to an existing table in our database.
>>>>>>> We had this set-up working previously with log4j-1.something in an
> MS
>>>>> SQL
>>>>>>> '05
>>>>>>> DB, all on Windows 2003 server (which we are migrating away from
> due
>>>>> to
>>>>>>> performance issues).
>>>>>>>
>>>>>>> Files within the web application:
>>>>>>> WEB-INF/lib/
>>>>>>>      log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
>>>>>>> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
>>>>>>> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
>>>>>>>      postgresql-jdbc.jar
>>>>>>>
>>>>>>>
>>>>>>> META-INF/context.xml:
>>>>>>> ---------------------
>>>>>>> <?xml version="1.0" encoding="utf-8"?>
>>>>>>> <context>
>>>>>>>  <resource
>>>>>>>      name="jdbc/loggingtst"
>>>>>>>      auth="Container"
>>>>>>>      type="javax.sql.DataSource"
>>>>>>>      username="*****"
>>>>>>>      password="*****"
>>>>>>>      driverClassName="org.postgresql.Driver"
>>>>>>>      url="jdbc:postgresql://foobar:5432/logging-tst"
>>>>>>>      maxTotal="20"
>>>>>>>      maxIdle="10"
>>>>>>>  />
>>>>>>> </context>
>>>>>>>
>>>>>>>
>>>>>>> WEB-INF/classes/log4j2.xml:
>>>>>>> ---------------------------
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <Configuration status="WARN">
>>>>>>>      ...
>>>>>>>  <Appenders>
>>>>>>>              ...
>>>>>>>      <JDBC name="DBAppender" tableName="logging.usage">
>>>>>>>          <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
>>>>>>>          <Column name="servername"   pattern="%X{servername}"/>
>>>>>>>          <Column name="fex"          pattern="%X{focexec}"/>
>>>>>>>          <Column name="parameters"   pattern="%X{parameters}"/>
>>>>>>>          <Column name="username"     pattern="%X{username}"/>
>>>>>>>          <Column name="duration"     pattern="%X{duration}"/>
>>>>>>>          <Column name="user_agent"   pattern="%X{user-agent}"/>
>>>>>>>      </JDBC>
>>>>>>>  </Appenders>
>>>>>>>  <Loggers>
>>>>>>>              ...
>>>>>>>      <Logger name="LogFilter" level="info" additivity="false">
>>>>>>>          <AppenderRef ref="DBAppender"/>
>>>>>>>      </Logger>
>>>>>>>
>>>>>>>      <Root level="error">
>>>>>>>          <AppenderRef ref="sysout" />
>>>>>>>      </Root>
>>>>>>>  </Loggers>
>>>>>>>
>>>>>>> </Configuration>
>>>>>>>
>>>>>>>
>>>>>>> WEB-INF/web.xml:
>>>>>>> ----------------
>>>>>>> ...
>>>>>>> <resource-ref>
>>>>>>>  <description>PostgreSQL logging table</description>
>>>>>>>  <res-ref-name>jdbc/loggingtst</res-ref-name>
>>>>>>>  <res-type>javax.sql.DataSource</res-type>
>>>>>>>  <res-auth>Container</res-auth>
>>>>>>> </resource-ref>
>>>>>>> ...
>>>>>>>
>>>>>>> With this, catalina.out contains:
>>>>>>>
>>>>>>> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
>>>>> JdbcDatabaseManager
>>>>>>> JdbcManager{name=FexAppender, bufferSize=0,
> tableName=logging.usage,
>>>>>>> columnConfigs=[{ name=servername, layout=%X{servername},
> literal=null,
>>>>>>> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
>>>>>>> timestamp=false }, { name=parameters, layout=%X{parameters},
>>>>> literal=null,
>>>>>>> timestamp=false }, { name=username, layout=%X{username},
> literal=null,
>>>>>>> timestamp=false }, { name=duration, layout=%X{duration},
> literal=null,
>>>>>>> timestamp=false }, { name=user_agent, layout=%X{user-agent},
>>>>> literal=null,
>>>>>>> timestamp=false }], columnMappings=[]} Could not perform database
>>>>> startup
>>>>>>> operations: java.sql.SQLException: Cannot create JDBC driver of
> class
>>>>> ''
>>>>>>> for connect URL 'null' java.sql.SQLException: Cannot create JDBC
>>>>> driver of
>>>>>>> class '' for connect URL 'null'
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>>>>>> (BasicDataSource.java:2186)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
>>>>>> (BasicDataSource.java:2066)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
>>>>>> (BasicDataSource.java:1525)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>
> org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
>>>>>> (DataSourceConnectionSource.java:51)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>
> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
>>>>>> (JdbcDatabaseManager.java:85)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup
>>>>>> (AbstractDatabaseManager.java:81)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
>>>>>> (AbstractDatabaseAppender.java:106)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.config.AbstractConfiguration.start
>>>>>> (AbstractConfiguration.java:265)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.LoggerContext.setConfiguration
>>>>>> (LoggerContext.java:547)
>>>>>>>      at
>>>>>>>
>>>>>
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
>>>>>> (Log4jContextFactory.java:240)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.config.Configurator.initialize
>>>>>> (Configurator.java:158)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
>>>>>> (Log4jWebInitializerImpl.java:168)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
>>>>>> (Log4jWebInitializerImpl.java:110)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
>>>>>> (Log4jServletContainerInitializer.java:57)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.catalina.core.StandardContext.startInternal
>>>>>> (StandardContext.java:5245)
>>>>>>>      at
>>>>>>>
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.catalina.core.ContainerBase.addChildInternal
>>>>>> (ContainerBase.java:754)
>>>>>>>      at
>>>>>>>
>>>>>
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
>>>>>>>      at
>>>>>>>
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>
>>>>> org.apache.catalina.startup.HostConfig.deployDescriptor
>> (HostConfig.java:629)
>>>>>>>      at
>>>>>>>
>>>>>>> org.apache.catalina.startup.HostConfig$DeployDescriptor.run
>>>>>> (HostConfig.java:1839)
>>>>>>>      at
>>>>>>>
>>>>>
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>>>>>>>      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>>>>>>>      at
>>>>>>>
>>>>>>> java.util.concurrent.ThreadPoolExecutor.runWorker
>>>>>> (ThreadPoolExecutor.java:1149)
>>>>>>>      at
>>>>>>>
>>>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run
>>>>>> (ThreadPoolExecutor.java:624)
>>>>>>>      at java.lang.Thread.run(Thread.java:748)
>>>>>>> Caused by: java.lang.NullPointerException
>>>>>>>      at org.postgresql.Driver.parseURL(Driver.java:551)
>>>>>>>      at org.postgresql.Driver.acceptsURL(Driver.java:472)
>>>>>>>      at java.sql.DriverManager.getDriver(DriverManager.java:299)
>>>>>>>      at
>>>>>>>
>>>>>>>
>>>>>>
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>>>>>> (BasicDataSource.java:2171)
>>>>>>>      ... 26 more
>>>>>>>
>>>>>>> (Ignore below company statement)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Alban  Hertroys
>>>>>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>>>>>>> [hidden email]
>>>>>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD
> Enschede,
>>>>> The
>>>>>>> Netherlands
>>>>>>> Chamber of Commerce number: 34223268
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> The information contained in this e-mail is intended solely for
> the
>>>>> use of
>>>>>>> the
>>>>>>> individual or entity to whom it is addressed. If you are not the
>>>>> intended
>>>>>>> recipient, you are hereby notified that any disclosure, copying,
>>>>>>> distribution
>>>>>>> or action in relation to the contents of this information is
> strictly
>>>>>>> prohibited and may be unlawful and request you to delete this
> message
>>>>> and
>>>>>>> any
>>>>>>> attachments and advise the sender by return e-mail. The
>>>>> confidentiality of
>>>>>>> this
>>>>>>> message is not warranted. Apollo Vredestein and its subsidiaries
> rule
>>>>> out
>>>>>>> any
>>>>>>> and every liability resulting from this or any other electronic
>>>>>>> transmission
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>         Please consider the environment before printing this
> e-mail
>>>>>>>
>>>>>>>
>>>>>>>
> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>> For additional commands, e-mail:
> [hidden email]
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>> Alban  Hertroys
>>>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>>>>> [hidden email]
>>>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD
> Enschede, The
>>>>> Netherlands
>>>>> Chamber of Commerce number: 34223268
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> The information contained in this e-mail is intended solely for the
> use of
>>>>> the
>>>>> individual or entity to whom it is addressed. If you are not the
> intended
>>>>> recipient, you are hereby notified that any disclosure, copying,
>>>>> distribution
>>>>> or action in relation to the contents of this information is
> strictly
>>>>> prohibited and may be unlawful and request you to delete this
> message and
>>>>> any
>>>>> attachments and advise the sender by return e-mail. The
> confidentiality of
>>>>> this
>>>>> message is not warranted. Apollo Vredestein and its subsidiaries
> rule out
>>>>> any
>>>>> and every liability resulting from this or any other electronic
>>>>> transmission
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>         Please consider the environment before printing this e-mail
>>>>>
>>>>>
>>>>>
> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>> --
>>>> Matt Sicker <[hidden email]>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>
>
>
> Alban  Hertroys    
> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E: [hidden email]
> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
> Netherlands
> Chamber of Commerce number: 34223268
>
>
>
>
> The information contained in this e-mail is intended solely for the use of the
> individual or entity to whom it is addressed. If you are not the intended
> recipient, you are hereby notified that any disclosure, copying, distribution
> or action in relation to the contents of this information is strictly
> prohibited and may be unlawful and request you to delete this message and any
> attachments and advise the sender by return e-mail. The confidentiality of this
> message is not warranted. Apollo Vredestein and its subsidiaries rule out any
> and every liability resulting from this or any other electronic transmission
>
>
>
>
>
>   Please consider the environment before printing this e-mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: JDBCAppender fails to pass connection URL string

Gary Gregory-4
In reply to this post by Ralph Goers
On Thu, Dec 12, 2019 at 9:55 AM Ralph Goers <[hidden email]>
wrote:

> I just looked at the JDBC unit tests and surprisingly didn’t see any that
> use a configuration file.
>

Here is a 'fancy' example (the kind of stuff I use at work):

https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml

Here are some more:

;-)

Gary


>
> Ralph
>
> > On Dec 12, 2019, at 7:54 AM, Matt Sicker <[hidden email]> wrote:
> >
> > Unit tests in the log4j project. All our components have examples in unit
> > tests.
> >
> > On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
> > [hidden email]> wrote:
> >
> >> "Gary Gregory" <[hidden email]> wrote on 2019-12-11 22:01:54:
> >>
> >>> CAUTION : External email. Do not click links or open  attachments
> >>> unless you recognize the sender and know the content is safe.
> >>>
> >>> AFK, sorry for the top-post. Have you looked at our unit tests? There
> >> might
> >>> be something there to help see what the usage pattern is for JNDI.
> >>
> >> You mean to say I should write some Java code to test the JNDI
> connection
> >> as defined in the Tomcat configuration? Or are the unit tests you refer
> to
> >> existing code that is available somewhere?
> >>
> >> Either way, I have no idea which unit tests you're referring to? I'm
> also
> >> not quite sure what I'm looking for here, I haven't done this before
> and I
> >> don't write Java code on a regular basis. Just created a few snippets to
> >> do small stuff here and there, such as this case where we're wrapping a
> >> servlet to have some logging of HTTP context information to a database
> >> table.
> >>
> >> There's no requirement here to do the logging through JNDI either; we
> used
> >> a direct connection through log4j.xml previously and that had some
> issues
> >> (mostly losing connection when the DB server got kicked). JNDI just
> seemed
> >> to be the easiest way to set up a connection pool for the JDBCAppender,
> >> but now it's starting to look like JNDI is anything but.
> >>
> >> Regards,
> >> Alban.
> >>
> >>
> >>> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
> >>> [hidden email]> wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> We're having a lot of trouble getting the JDBCAppender to write to our
> >>>> PostgreSQL database. There's probably a configuration error somewhere,
> >> but
> >>>> we haven't been able to find it. And I have been searching and trying
> >> for
> >>>> several days now, with no progress at all.
> >>>> Even though we specify a connection URL in the JDNI source (see
> >> below), it
> >>>> always ends with the JDBCAppender complaining that:
> >>>>        java.sql.SQLException: Cannot create JDBC driver of class ''
> >> for
> >>>> connect URL 'null'
> >>>>
> >>>> The Appender should write the data to our database at server "foobar",
> >>>> database "logging-tst". Using the same credentials in SquirrelSQL,
> >> with
> >>>> the same JDBC driver, I can connect to that database and query the
> >> table
> >>>> specified in the log4j.xml (schema: "logging", table: "usage"; names
> >> being
> >>>> case-insensitive).
> >>>>
> >>>> Any pointers would be appreciated.
> >>>>
> >>>> Environment:
> >>>> - Centos 7
> >>>> - Apache Tomcat 8.5.32
> >>>> - log4j-2.11
> >>>>
> >>>> We created a servlet HTTP filter into a JAR, compiled against:
> >>>> WEB-INF/lib:
> >>>>        log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
> >>>>        servlet-api.jar
> >>>>
> >>>> This servlet put()'s certain fields into the ThreadContext, which we
> >> then
> >>>> attempt to access through %X{...} in the log4j2.xml, appending those
> >>>> fields as a
> >>>> row to an existing table in our database.
> >>>> We had this set-up working previously with log4j-1.something in an MS
> >> SQL
> >>>> '05
> >>>> DB, all on Windows 2003 server (which we are migrating away from due
> >> to
> >>>> performance issues).
> >>>>
> >>>> Files within the web application:
> >>>> WEB-INF/lib/
> >>>>        log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
> >>>> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
> >>>> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
> >>>>        postgresql-jdbc.jar
> >>>>
> >>>>
> >>>> META-INF/context.xml:
> >>>> ---------------------
> >>>> <?xml version="1.0" encoding="utf-8"?>
> >>>> <context>
> >>>>    <resource
> >>>>        name="jdbc/loggingtst"
> >>>>        auth="Container"
> >>>>        type="javax.sql.DataSource"
> >>>>        username="*****"
> >>>>        password="*****"
> >>>>        driverClassName="org.postgresql.Driver"
> >>>>        url="jdbc:postgresql://foobar:5432/logging-tst"
> >>>>        maxTotal="20"
> >>>>        maxIdle="10"
> >>>>    />
> >>>> </context>
> >>>>
> >>>>
> >>>> WEB-INF/classes/log4j2.xml:
> >>>> ---------------------------
> >>>> <?xml version="1.0" encoding="UTF-8"?>
> >>>> <Configuration status="WARN">
> >>>>        ...
> >>>>    <Appenders>
> >>>>                ...
> >>>>        <JDBC name="DBAppender" tableName="logging.usage">
> >>>>            <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
> >>>>            <Column name="servername"   pattern="%X{servername}"/>
> >>>>            <Column name="fex"          pattern="%X{focexec}"/>
> >>>>            <Column name="parameters"   pattern="%X{parameters}"/>
> >>>>            <Column name="username"     pattern="%X{username}"/>
> >>>>            <Column name="duration"     pattern="%X{duration}"/>
> >>>>            <Column name="user_agent"   pattern="%X{user-agent}"/>
> >>>>        </JDBC>
> >>>>    </Appenders>
> >>>>    <Loggers>
> >>>>                ...
> >>>>        <Logger name="LogFilter" level="info" additivity="false">
> >>>>            <AppenderRef ref="DBAppender"/>
> >>>>        </Logger>
> >>>>
> >>>>        <Root level="error">
> >>>>            <AppenderRef ref="sysout" />
> >>>>        </Root>
> >>>>    </Loggers>
> >>>>
> >>>> </Configuration>
> >>>>
> >>>>
> >>>> WEB-INF/web.xml:
> >>>> ----------------
> >>>>  ...
> >>>>  <resource-ref>
> >>>>    <description>PostgreSQL logging table</description>
> >>>>    <res-ref-name>jdbc/loggingtst</res-ref-name>
> >>>>    <res-type>javax.sql.DataSource</res-type>
> >>>>    <res-auth>Container</res-auth>
> >>>>  </resource-ref>
> >>>>  ...
> >>>>
> >>>> With this, catalina.out contains:
> >>>>
> >>>> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
> >> JdbcDatabaseManager
> >>>> JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
> >>>> columnConfigs=[{ name=servername, layout=%X{servername}, literal=null,
> >>>> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
> >>>> timestamp=false }, { name=parameters, layout=%X{parameters},
> >> literal=null,
> >>>> timestamp=false }, { name=username, layout=%X{username}, literal=null,
> >>>> timestamp=false }, { name=duration, layout=%X{duration}, literal=null,
> >>>> timestamp=false }, { name=user_agent, layout=%X{user-agent},
> >> literal=null,
> >>>> timestamp=false }], columnMappings=[]} Could not perform database
> >> startup
> >>>> operations: java.sql.SQLException: Cannot create JDBC driver of class
> >> ''
> >>>> for connect URL 'null' java.sql.SQLException: Cannot create JDBC
> >> driver of
> >>>> class '' for connect URL 'null'
> >>>>        at
> >>>>
> >>>>
> >>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> >>> (BasicDataSource.java:2186)
> >>>>        at
> >>>>
> >>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
> >>> (BasicDataSource.java:2066)
> >>>>        at
> >>>>
> >>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
> >>> (BasicDataSource.java:1525)
> >>>>        at
> >>>>
> >>>>
> >>>
> >>
> >>
> org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
> >>> (DataSourceConnectionSource.java:51)
> >>>>        at
> >>>>
> >>>>
> >>>
> >>
> >>
> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
> >>> (JdbcDatabaseManager.java:85)
> >>>>        at
> >>>>
> >>>>
> >>>
> >>
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup
> >>> (AbstractDatabaseManager.java:81)
> >>>>        at
> >>>>
> >>>>
> >>>
> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
> >>> (AbstractDatabaseAppender.java:106)
> >>>>        at
> >>>>
> >>>> org.apache.logging.log4j.core.config.AbstractConfiguration.start
> >>> (AbstractConfiguration.java:265)
> >>>>        at
> >>>>
> >>>> org.apache.logging.log4j.core.LoggerContext.setConfiguration
> >>> (LoggerContext.java:547)
> >>>>        at
> >>>>
> >>
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
> >>>>        at
> >>>>
> >>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
> >>> (Log4jContextFactory.java:240)
> >>>>        at
> >>>>
> >>>> org.apache.logging.log4j.core.config.Configurator.initialize
> >>> (Configurator.java:158)
> >>>>        at
> >>>>
> >>>>
> >>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
> >>> (Log4jWebInitializerImpl.java:168)
> >>>>        at
> >>>>
> >>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
> >>> (Log4jWebInitializerImpl.java:110)
> >>>>        at
> >>>>
> >>>>
> >>> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
> >>> (Log4jServletContainerInitializer.java:57)
> >>>>        at
> >>>>
> >>>> org.apache.catalina.core.StandardContext.startInternal
> >>> (StandardContext.java:5245)
> >>>>        at
> >>>> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >>>>        at
> >>>>
> >>>> org.apache.catalina.core.ContainerBase.addChildInternal
> >>> (ContainerBase.java:754)
> >>>>        at
> >>>>
> >> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
> >>>>        at
> >>>> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
> >>>>        at
> >>>>
> >>>>
> >>
> >>
> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
> >>>>        at
> >>>>
> >>>> org.apache.catalina.startup.HostConfig$DeployDescriptor.run
> >>> (HostConfig.java:1839)
> >>>>        at
> >>>>
> >> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> >>>>        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> >>>>        at
> >>>>
> >>>> java.util.concurrent.ThreadPoolExecutor.runWorker
> >>> (ThreadPoolExecutor.java:1149)
> >>>>        at
> >>>>
> >>>> java.util.concurrent.ThreadPoolExecutor$Worker.run
> >>> (ThreadPoolExecutor.java:624)
> >>>>        at java.lang.Thread.run(Thread.java:748)
> >>>> Caused by: java.lang.NullPointerException
> >>>>        at org.postgresql.Driver.parseURL(Driver.java:551)
> >>>>        at org.postgresql.Driver.acceptsURL(Driver.java:472)
> >>>>        at java.sql.DriverManager.getDriver(DriverManager.java:299)
> >>>>        at
> >>>>
> >>>>
> >>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
> >>> (BasicDataSource.java:2171)
> >>>>        ... 26 more
> >>>>
> >>>> (Ignore below company statement)
> >>>>
> >>>>
> >>>>
> >>>> Alban  Hertroys
> >>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> >>>> [hidden email]
> >>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
> >> The
> >>>> Netherlands
> >>>> Chamber of Commerce number: 34223268
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> The information contained in this e-mail is intended solely for the
> >> use of
> >>>> the
> >>>> individual or entity to whom it is addressed. If you are not the
> >> intended
> >>>> recipient, you are hereby notified that any disclosure, copying,
> >>>> distribution
> >>>> or action in relation to the contents of this information is strictly
> >>>> prohibited and may be unlawful and request you to delete this message
> >> and
> >>>> any
> >>>> attachments and advise the sender by return e-mail. The
> >> confidentiality of
> >>>> this
> >>>> message is not warranted. Apollo Vredestein and its subsidiaries rule
> >> out
> >>>> any
> >>>> and every liability resulting from this or any other electronic
> >>>> transmission
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>           Please consider the environment before printing this e-mail
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: [hidden email]
> >>>> For additional commands, e-mail: [hidden email]
> >>>>
> >>>>
> >>
> >>
> >> Alban  Hertroys
> >> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
> >> [hidden email]
> >> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
> The
> >> Netherlands
> >> Chamber of Commerce number: 34223268
> >>
> >>
> >>
> >>
> >> The information contained in this e-mail is intended solely for the use
> of
> >> the
> >> individual or entity to whom it is addressed. If you are not the
> intended
> >> recipient, you are hereby notified that any disclosure, copying,
> >> distribution
> >> or action in relation to the contents of this information is strictly
> >> prohibited and may be unlawful and request you to delete this message
> and
> >> any
> >> attachments and advise the sender by return e-mail. The confidentiality
> of
> >> this
> >> message is not warranted. Apollo Vredestein and its subsidiaries rule
> out
> >> any
> >> and every liability resulting from this or any other electronic
> >> transmission
> >>
> >>
> >>
> >>
> >>
> >>           Please consider the environment before printing this e-mail
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >> --
> > Matt Sicker <[hidden email]>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: JDBCAppender fails to pass connection URL string

Gary Gregory-4
The more:

https://github.com/apache/logging-log4j2/tree/release-2.x/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc

Gary


On Thu, Dec 12, 2019 at 3:54 PM Gary Gregory <[hidden email]> wrote:

> On Thu, Dec 12, 2019 at 9:55 AM Ralph Goers <[hidden email]>
> wrote:
>
>> I just looked at the JDBC unit tests and surprisingly didn’t see any that
>> use a configuration file.
>>
>
> Here is a 'fancy' example (the kind of stuff I use at work):
>
>
> https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml
>
> Here are some more:
>
> ;-)
>
> Gary
>
>
>>
>> Ralph
>>
>> > On Dec 12, 2019, at 7:54 AM, Matt Sicker <[hidden email]> wrote:
>> >
>> > Unit tests in the log4j project. All our components have examples in
>> unit
>> > tests.
>> >
>> > On Thu, Dec 12, 2019 at 04:26 Alban Hertroys <
>> > [hidden email]> wrote:
>> >
>> >> "Gary Gregory" <[hidden email]> wrote on 2019-12-11 22:01:54:
>> >>
>> >>> CAUTION : External email. Do not click links or open  attachments
>> >>> unless you recognize the sender and know the content is safe.
>> >>>
>> >>> AFK, sorry for the top-post. Have you looked at our unit tests? There
>> >> might
>> >>> be something there to help see what the usage pattern is for JNDI.
>> >>
>> >> You mean to say I should write some Java code to test the JNDI
>> connection
>> >> as defined in the Tomcat configuration? Or are the unit tests you
>> refer to
>> >> existing code that is available somewhere?
>> >>
>> >> Either way, I have no idea which unit tests you're referring to? I'm
>> also
>> >> not quite sure what I'm looking for here, I haven't done this before
>> and I
>> >> don't write Java code on a regular basis. Just created a few snippets
>> to
>> >> do small stuff here and there, such as this case where we're wrapping a
>> >> servlet to have some logging of HTTP context information to a database
>> >> table.
>> >>
>> >> There's no requirement here to do the logging through JNDI either; we
>> used
>> >> a direct connection through log4j.xml previously and that had some
>> issues
>> >> (mostly losing connection when the DB server got kicked). JNDI just
>> seemed
>> >> to be the easiest way to set up a connection pool for the JDBCAppender,
>> >> but now it's starting to look like JNDI is anything but.
>> >>
>> >> Regards,
>> >> Alban.
>> >>
>> >>
>> >>> On Tue, Dec 10, 2019, 06:02 Alban Hertroys <
>> >>> [hidden email]> wrote:
>> >>>
>> >>>> Hi,
>> >>>>
>> >>>> We're having a lot of trouble getting the JDBCAppender to write to
>> our
>> >>>> PostgreSQL database. There's probably a configuration error
>> somewhere,
>> >> but
>> >>>> we haven't been able to find it. And I have been searching and trying
>> >> for
>> >>>> several days now, with no progress at all.
>> >>>> Even though we specify a connection URL in the JDNI source (see
>> >> below), it
>> >>>> always ends with the JDBCAppender complaining that:
>> >>>>        java.sql.SQLException: Cannot create JDBC driver of class ''
>> >> for
>> >>>> connect URL 'null'
>> >>>>
>> >>>> The Appender should write the data to our database at server
>> "foobar",
>> >>>> database "logging-tst". Using the same credentials in SquirrelSQL,
>> >> with
>> >>>> the same JDBC driver, I can connect to that database and query the
>> >> table
>> >>>> specified in the log4j.xml (schema: "logging", table: "usage"; names
>> >> being
>> >>>> case-insensitive).
>> >>>>
>> >>>> Any pointers would be appreciated.
>> >>>>
>> >>>> Environment:
>> >>>> - Centos 7
>> >>>> - Apache Tomcat 8.5.32
>> >>>> - log4j-2.11
>> >>>>
>> >>>> We created a servlet HTTP filter into a JAR, compiled against:
>> >>>> WEB-INF/lib:
>> >>>>        log4j-api-2.11.0.jar  log4j-core-2.11.0.jar
>> >>>>        servlet-api.jar
>> >>>>
>> >>>> This servlet put()'s certain fields into the ThreadContext, which we
>> >> then
>> >>>> attempt to access through %X{...} in the log4j2.xml, appending those
>> >>>> fields as a
>> >>>> row to an existing table in our database.
>> >>>> We had this set-up working previously with log4j-1.something in an MS
>> >> SQL
>> >>>> '05
>> >>>> DB, all on Windows 2003 server (which we are migrating away from due
>> >> to
>> >>>> performance issues).
>> >>>>
>> >>>> Files within the web application:
>> >>>> WEB-INF/lib/
>> >>>>        log4j-1.2-api-2.11.0.jar  log4j-api-2.11.0.jar
>> >>>> log4j-core-2.11.0.jar  log4j-jcl-2.11.0.jar  log4j-jul-2.11.0.jar
>> >>>> log4j-slf4j-impl-2.11.0.jar  log4j-web-2.11.0.jar
>> >>>>        postgresql-jdbc.jar
>> >>>>
>> >>>>
>> >>>> META-INF/context.xml:
>> >>>> ---------------------
>> >>>> <?xml version="1.0" encoding="utf-8"?>
>> >>>> <context>
>> >>>>    <resource
>> >>>>        name="jdbc/loggingtst"
>> >>>>        auth="Container"
>> >>>>        type="javax.sql.DataSource"
>> >>>>        username="*****"
>> >>>>        password="*****"
>> >>>>        driverClassName="org.postgresql.Driver"
>> >>>>        url="jdbc:postgresql://foobar:5432/logging-tst"
>> >>>>        maxTotal="20"
>> >>>>        maxIdle="10"
>> >>>>    />
>> >>>> </context>
>> >>>>
>> >>>>
>> >>>> WEB-INF/classes/log4j2.xml:
>> >>>> ---------------------------
>> >>>> <?xml version="1.0" encoding="UTF-8"?>
>> >>>> <Configuration status="WARN">
>> >>>>        ...
>> >>>>    <Appenders>
>> >>>>                ...
>> >>>>        <JDBC name="DBAppender" tableName="logging.usage">
>> >>>>            <DataSource jndiName="java:/comp/env/jdbc/loggingtst"/>
>> >>>>            <Column name="servername"   pattern="%X{servername}"/>
>> >>>>            <Column name="fex"          pattern="%X{focexec}"/>
>> >>>>            <Column name="parameters"   pattern="%X{parameters}"/>
>> >>>>            <Column name="username"     pattern="%X{username}"/>
>> >>>>            <Column name="duration"     pattern="%X{duration}"/>
>> >>>>            <Column name="user_agent"   pattern="%X{user-agent}"/>
>> >>>>        </JDBC>
>> >>>>    </Appenders>
>> >>>>    <Loggers>
>> >>>>                ...
>> >>>>        <Logger name="LogFilter" level="info" additivity="false">
>> >>>>            <AppenderRef ref="DBAppender"/>
>> >>>>        </Logger>
>> >>>>
>> >>>>        <Root level="error">
>> >>>>            <AppenderRef ref="sysout" />
>> >>>>        </Root>
>> >>>>    </Loggers>
>> >>>>
>> >>>> </Configuration>
>> >>>>
>> >>>>
>> >>>> WEB-INF/web.xml:
>> >>>> ----------------
>> >>>>  ...
>> >>>>  <resource-ref>
>> >>>>    <description>PostgreSQL logging table</description>
>> >>>>    <res-ref-name>jdbc/loggingtst</res-ref-name>
>> >>>>    <res-type>javax.sql.DataSource</res-type>
>> >>>>    <res-auth>Container</res-auth>
>> >>>>  </resource-ref>
>> >>>>  ...
>> >>>>
>> >>>> With this, catalina.out contains:
>> >>>>
>> >>>> 2019-12-09 17:38:16,460 localhost-startStop-1 ERROR
>> >> JdbcDatabaseManager
>> >>>> JdbcManager{name=FexAppender, bufferSize=0, tableName=logging.usage,
>> >>>> columnConfigs=[{ name=servername, layout=%X{servername},
>> literal=null,
>> >>>> timestamp=false }, { name=fex, layout=%X{focexec}, literal=null,
>> >>>> timestamp=false }, { name=parameters, layout=%X{parameters},
>> >> literal=null,
>> >>>> timestamp=false }, { name=username, layout=%X{username},
>> literal=null,
>> >>>> timestamp=false }, { name=duration, layout=%X{duration},
>> literal=null,
>> >>>> timestamp=false }, { name=user_agent, layout=%X{user-agent},
>> >> literal=null,
>> >>>> timestamp=false }], columnMappings=[]} Could not perform database
>> >> startup
>> >>>> operations: java.sql.SQLException: Cannot create JDBC driver of class
>> >> ''
>> >>>> for connect URL 'null' java.sql.SQLException: Cannot create JDBC
>> >> driver of
>> >>>> class '' for connect URL 'null'
>> >>>>        at
>> >>>>
>> >>>>
>> >>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>> >>> (BasicDataSource.java:2186)
>> >>>>        at
>> >>>>
>> >>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource
>> >>> (BasicDataSource.java:2066)
>> >>>>        at
>> >>>>
>> >>>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection
>> >>> (BasicDataSource.java:1525)
>> >>>>        at
>> >>>>
>> >>>>
>> >>>
>> >>
>> >>
>> org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.getConnection
>> >>> (DataSourceConnectionSource.java:51)
>> >>>>        at
>> >>>>
>> >>>>
>> >>>
>> >>
>> >>
>> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.startupInternal
>> >>> (JdbcDatabaseManager.java:85)
>> >>>>        at
>> >>>>
>> >>>>
>> >>>
>> >>
>> org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup
>> >>> (AbstractDatabaseManager.java:81)
>> >>>>        at
>> >>>>
>> >>>>
>> >>>
>> org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start
>> >>> (AbstractDatabaseAppender.java:106)
>> >>>>        at
>> >>>>
>> >>>> org.apache.logging.log4j.core.config.AbstractConfiguration.start
>> >>> (AbstractConfiguration.java:265)
>> >>>>        at
>> >>>>
>> >>>> org.apache.logging.log4j.core.LoggerContext.setConfiguration
>> >>> (LoggerContext.java:547)
>> >>>>        at
>> >>>>
>> >>
>> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
>> >>>>        at
>> >>>>
>> >>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext
>> >>> (Log4jContextFactory.java:240)
>> >>>>        at
>> >>>>
>> >>>> org.apache.logging.log4j.core.config.Configurator.initialize
>> >>> (Configurator.java:158)
>> >>>>        at
>> >>>>
>> >>>>
>> >>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi
>> >>> (Log4jWebInitializerImpl.java:168)
>> >>>>        at
>> >>>>
>> >>>> org.apache.logging.log4j.web.Log4jWebInitializerImpl.start
>> >>> (Log4jWebInitializerImpl.java:110)
>> >>>>        at
>> >>>>
>> >>>>
>> >>>
>> org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup
>> >>> (Log4jServletContainerInitializer.java:57)
>> >>>>        at
>> >>>>
>> >>>> org.apache.catalina.core.StandardContext.startInternal
>> >>> (StandardContext.java:5245)
>> >>>>        at
>> >>>> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>> >>>>        at
>> >>>>
>> >>>> org.apache.catalina.core.ContainerBase.addChildInternal
>> >>> (ContainerBase.java:754)
>> >>>>        at
>> >>>>
>> >> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
>> >>>>        at
>> >>>> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
>> >>>>        at
>> >>>>
>> >>>>
>> >>
>> >>
>> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
>> >>>>        at
>> >>>>
>> >>>> org.apache.catalina.startup.HostConfig$DeployDescriptor.run
>> >>> (HostConfig.java:1839)
>> >>>>        at
>> >>>>
>> >> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>> >>>>        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>> >>>>        at
>> >>>>
>> >>>> java.util.concurrent.ThreadPoolExecutor.runWorker
>> >>> (ThreadPoolExecutor.java:1149)
>> >>>>        at
>> >>>>
>> >>>> java.util.concurrent.ThreadPoolExecutor$Worker.run
>> >>> (ThreadPoolExecutor.java:624)
>> >>>>        at java.lang.Thread.run(Thread.java:748)
>> >>>> Caused by: java.lang.NullPointerException
>> >>>>        at org.postgresql.Driver.parseURL(Driver.java:551)
>> >>>>        at org.postgresql.Driver.acceptsURL(Driver.java:472)
>> >>>>        at java.sql.DriverManager.getDriver(DriverManager.java:299)
>> >>>>        at
>> >>>>
>> >>>>
>> >>> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory
>> >>> (BasicDataSource.java:2171)
>> >>>>        ... 26 more
>> >>>>
>> >>>> (Ignore below company statement)
>> >>>>
>> >>>>
>> >>>>
>> >>>> Alban  Hertroys
>> >>>> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>> >>>> [hidden email]
>> >>>> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD
>> Enschede,
>> >> The
>> >>>> Netherlands
>> >>>> Chamber of Commerce number: 34223268
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> The information contained in this e-mail is intended solely for the
>> >> use of
>> >>>> the
>> >>>> individual or entity to whom it is addressed. If you are not the
>> >> intended
>> >>>> recipient, you are hereby notified that any disclosure, copying,
>> >>>> distribution
>> >>>> or action in relation to the contents of this information is strictly
>> >>>> prohibited and may be unlawful and request you to delete this message
>> >> and
>> >>>> any
>> >>>> attachments and advise the sender by return e-mail. The
>> >> confidentiality of
>> >>>> this
>> >>>> message is not warranted. Apollo Vredestein and its subsidiaries rule
>> >> out
>> >>>> any
>> >>>> and every liability resulting from this or any other electronic
>> >>>> transmission
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>           Please consider the environment before printing this e-mail
>> >>>>
>> >>>>
>> >>>> ---------------------------------------------------------------------
>> >>>> To unsubscribe, e-mail: [hidden email]
>> >>>> For additional commands, e-mail: [hidden email]
>> >>>>
>> >>>>
>> >>
>> >>
>> >> Alban  Hertroys
>> >> D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E:
>> >> [hidden email]
>> >> Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede,
>> The
>> >> Netherlands
>> >> Chamber of Commerce number: 34223268
>> >>
>> >>
>> >>
>> >>
>> >> The information contained in this e-mail is intended solely for the
>> use of
>> >> the
>> >> individual or entity to whom it is addressed. If you are not the
>> intended
>> >> recipient, you are hereby notified that any disclosure, copying,
>> >> distribution
>> >> or action in relation to the contents of this information is strictly
>> >> prohibited and may be unlawful and request you to delete this message
>> and
>> >> any
>> >> attachments and advise the sender by return e-mail. The
>> confidentiality of
>> >> this
>> >> message is not warranted. Apollo Vredestein and its subsidiaries rule
>> out
>> >> any
>> >> and every liability resulting from this or any other electronic
>> >> transmission
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>           Please consider the environment before printing this e-mail
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: [hidden email]
>> >> For additional commands, e-mail: [hidden email]
>> >>
>> >> --
>> > Matt Sicker <[hidden email]>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
Reply | Threaded
Open this post in threaded view
|

Betr: Re: JDBCAppender fails to pass connection URL string

Alban Hertroys
"Gary Gregory" <[hidden email]> wrote on 2019-12-12 21:54:27:

> The more:
>
> https://github.com/apache/logging-log4j2/tree/release-2.x/log4j-
> core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc
>
> Gary


Thanks for the examples, much appreciated. It confirmed that I was
probably doing things correctly on the log4j front, at least.

As it turns out, the problem was with Tomcat's documentation about how to
set up a JNDI connection. They refer to a META-INF/context.xml file in the
web-app directory, but in our case the context files are located in the
${CATALINA_OUT}/conf/Catalina/localhost directory and point to the
locations where the web-app files can be found. Placing the <Resource
.../> there got us rid of the error about the empty jdbc URL and driver
name, at least.

I'm almost there. I can select from the database with a slightly expanded
variation on my previous Java class, so we are able to connect at least -
now to figure out why the actual webapp is not logging anything...

Should be easy enough to add a log4j JDBCAppender for my test-webapp.

> On Thu, Dec 12, 2019 at 3:54 PM Gary Gregory <[hidden email]>
wrote:
>
> > On Thu, Dec 12, 2019 at 9:55 AM Ralph Goers
<[hidden email]>
> > wrote:
> >
> >> I just looked at the JDBC unit tests and surprisingly didn’t see any
that

> >> use a configuration file.
> >>
> >
> > Here is a 'fancy' example (the kind of stuff I use at work):
> >
> >
> > https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-
> jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml
> >
> > Here are some more:
> >
> > ;-)
> >
> > Gary


This is what now remains of the configuration.

${CATALINA_OUT}/conf/Catalina/localhost/mywebapp_context.xml

> >> >>>> ---------------------
> >> >>>> <?xml version="1.0" encoding="utf-8"?>
> >> >>>> <context docBase="/webapps/foo" path="/foo">
> >> >>>>    <resource
> >> >>>>        name="jdbc/loggingtst"
> >> >>>>        auth="Container"
> >> >>>>        type="javax.sql.DataSource"
> >> >>>>        username="*****"
> >> >>>>        password="*****"
> >> >>>>        driverClassName="org.postgresql.Driver"
> >> >>>>        url="jdbc:postgresql://foobar:5432/logging-tst"
> >> >>>>        maxTotal="20"
> >> >>>>        maxIdle="10"
> >> >>>>    />
> >> >>>> </context>
> >> >>>>
> >> >>>>
> >> >>>> WEB-INF/classes/log4j2.xml:
> >> >>>> ---------------------------
> >> >>>> <?xml version="1.0" encoding="UTF-8"?>
> >> >>>> <Configuration status="WARN">
> >> >>>>        ...
> >> >>>>    <Appenders>
> >> >>>>                ...
> >> >>>>        <JDBC name="DBAppender" tableName="logging.usage">
> >> >>>>            <DataSource
jndiName="java:/comp/env/jdbc/loggingtst"/>

> >> >>>>            <Column name="servername" pattern="%X{servername}"/>
> >> >>>>            <Column name="fex"          pattern="%X{focexec}"/>
> >> >>>>            <Column name="parameters" pattern="%X{parameters}"/>
> >> >>>>            <Column name="username"     pattern="%X{username}"/>
> >> >>>>            <Column name="duration"     pattern="%X{duration}"/>
> >> >>>>            <Column name="user_agent" pattern="%X{user-agent}"/>
> >> >>>>        </JDBC>
> >> >>>>    </Appenders>
> >> >>>>    <Loggers>
> >> >>>>                ...
> >> >>>>        <Logger name="LogFilter" level="info" additivity="false">
> >> >>>>            <AppenderRef ref="DBAppender"/>
> >> >>>>        </Logger>
> >> >>>>
> >> >>>>        <Root level="error">
> >> >>>>            <AppenderRef ref="sysout" />
> >> >>>>        </Root>
> >> >>>>    </Loggers>
> >> >>>>
> >> >>>> </Configuration>
> >> >>>>



Alban  Hertroys    
D: +31 (0)53 4 888 888  | T: +31 (0)53 4888 888 | E: [hidden email]
Apollo Vredestein B.V.| Ir. E.L.C. Schiffstraat 370, 7547 RD Enschede, The
Netherlands
Chamber of Commerce number: 34223268

 
       
                 
The information contained in this e-mail is intended solely for the use of the
individual or entity to whom it is addressed. If you are not the intended
recipient, you are hereby notified that any disclosure, copying, distribution
or action in relation to the contents of this information is strictly
prohibited and may be unlawful and request you to delete this message and any
attachments and advise the sender by return e-mail. The confidentiality of this
message is not warranted. Apollo Vredestein and its subsidiaries rule out any
and every liability resulting from this or any other electronic transmission



       
               
           Please consider the environment before printing this e-mail

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]