You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "gaurav9822@gmail.com" <ga...@gmail.com> on 2017/11/30 12:36:45 UTC

How do I create jdbc appender using programmatic configuration?

Hi log4j2 users,

I want to create jdbc appender using programmatic configuration.

Please provide the programmatic configuration if you already have or guide me to create it.

P.S. I am able to create JDBCAppender using xml configuration 

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: How do I create jdbc appender using programmatic configuration?

Posted by Matt Sicker <bo...@gmail.com>.
It looks like you're mixing two APIs together. You're instantiating plugins
directly and using the configuration builder API at the same time here.

On 1 December 2017 at 03:56, gaurav9822@gmail.com <ga...@gmail.com>
wrote:

>
>
> On 2017-12-01 14:34, "gaurav9822@gmail.com"<ga...@gmail.com> wrote:
> >
> >
> > On 2017-11-30 23:07, Matt Sicker <bo...@gmail.com> wrote:
> > > You should be able to create one the same way you create any other
> appender
> > > using programmatic configuration.
> > >
> > > On 30 November 2017 at 06:36, gaurav9822@gmail.com <
> gaurav9822@gmail.com>
> > > wrote:
> > >
> > > > Hi log4j2 users,
> > > >
> > > > I want to create jdbc appender using programmatic configuration.
> > > >
> > > > Please provide the programmatic configuration if you already have or
> guide
> > > > me to create it.
> > > >
> > > > P.S. I am able to create JDBCAppender using xml configuration
> > > >
> > > > Thanks
> > > >
> > > > ------------------------------------------------------------
> ---------
> > > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > > >
> > > >
> > >
> > >
> > > --
> > > Matt Sicker <bo...@gmail.com>
> > > Hi Matt,
> >
> > I am able to add "tableName" attribute for JDBC AppenderComponentBuilder
> > But not the remaining stuff like
> > ConnectionFactory class,method and Columns.
> >
> > Please help
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> > What I've tried until now:
>
>
> ConfigurationBuilder<BuiltConfiguration> builder =
>     ConfigurationBuilderFactory.newConfigurationBuilder();
> builder.setConfigurationName("myConfig");
> builder.setStatusLevel(Level.ERROR);
>
> ColumnConfig[] columnConfigs =
>     new ColumnConfig[] {
>       ColumnConfig.newBuilder()
>           // .setConfiguration(builder.)
>           .setName("myUsername")
>           .setPattern("")
>           .setLiteral("%X{username}")
>           .setEventTimestamp(false)
>           .setUnicode(false)
>           .setClob(false)
>           .build(),
>       ColumnConfig.newBuilder()
>           // .setConfiguration(this)
>           .setName("myAction")
>           .setPattern("%X{action}")
>           .setLiteral(null)
>           .setEventTimestamp(false)
>           .setUnicode(false)
>           .setClob(false)
>           .build(),
>       ColumnConfig.newBuilder()
>           // .setConfiguration(this)
>           .setName("myTimeStamp")
>           .setPattern(null)
>           .setLiteral(null)
>           .setEventTimestamp(true)
>           .setUnicode(false)
>           .setClob(false)
>           .build()
>     };
>
> ConnectionSource factoryMethodConnectionSource =
>     FactoryMethodConnectionSource.createConnectionSource(
>         "com.database.ConnectionFactory", "getDatabaseConnection");
>
> AppenderComponentBuilder appenderBuilder =
>     builder
>         .newAppender("databaseAppender", "JDBC")
>         .addAttribute("tableName", “myTable”);
>
> builder.add(appenderBuilder);
>
> builder.add(
>     builder
>         .newLogger("DbLogger", Level.DEBUG)
>         .add(builder.newAppenderRef("databaseAppender"))
>         .addAttribute("additivity", false));
> LoggerContext ctx = Configurator.initialize(builder.build());
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: How do I create jdbc appender using programmatic configuration?

Posted by "gaurav9822@gmail.com" <ga...@gmail.com>.

On 2017-12-01 14:34, "gaurav9822@gmail.com"<ga...@gmail.com> wrote: 
> 
> 
> On 2017-11-30 23:07, Matt Sicker <bo...@gmail.com> wrote: 
> > You should be able to create one the same way you create any other appender
> > using programmatic configuration.
> > 
> > On 30 November 2017 at 06:36, gaurav9822@gmail.com <ga...@gmail.com>
> > wrote:
> > 
> > > Hi log4j2 users,
> > >
> > > I want to create jdbc appender using programmatic configuration.
> > >
> > > Please provide the programmatic configuration if you already have or guide
> > > me to create it.
> > >
> > > P.S. I am able to create JDBCAppender using xml configuration
> > >
> > > Thanks
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > >
> > >
> > 
> > 
> > -- 
> > Matt Sicker <bo...@gmail.com>
> > Hi Matt,
> 
> I am able to add "tableName" attribute for JDBC AppenderComponentBuilder
> But not the remaining stuff like 
> ConnectionFactory class,method and Columns.
> 
> Please help
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> What I've tried until now:


ConfigurationBuilder<BuiltConfiguration> builder =
    ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setConfigurationName("myConfig");
builder.setStatusLevel(Level.ERROR);

ColumnConfig[] columnConfigs =
    new ColumnConfig[] {
      ColumnConfig.newBuilder()
          // .setConfiguration(builder.)
          .setName("myUsername")
          .setPattern("")
          .setLiteral("%X{username}")
          .setEventTimestamp(false)
          .setUnicode(false)
          .setClob(false)
          .build(),
      ColumnConfig.newBuilder()
          // .setConfiguration(this)
          .setName("myAction")
          .setPattern("%X{action}")
          .setLiteral(null)
          .setEventTimestamp(false)
          .setUnicode(false)
          .setClob(false)
          .build(),
      ColumnConfig.newBuilder()
          // .setConfiguration(this)
          .setName("myTimeStamp")
          .setPattern(null)
          .setLiteral(null)
          .setEventTimestamp(true)
          .setUnicode(false)
          .setClob(false)
          .build()
    };

ConnectionSource factoryMethodConnectionSource =
    FactoryMethodConnectionSource.createConnectionSource(
        "com.database.ConnectionFactory", "getDatabaseConnection");

AppenderComponentBuilder appenderBuilder =
    builder
        .newAppender("databaseAppender", "JDBC")
        .addAttribute("tableName", “myTable”);

builder.add(appenderBuilder);

builder.add(
    builder
        .newLogger("DbLogger", Level.DEBUG)
        .add(builder.newAppenderRef("databaseAppender"))
        .addAttribute("additivity", false));
LoggerContext ctx = Configurator.initialize(builder.build());


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: How do I create jdbc appender using programmatic configuration?

Posted by "gaurav9822@gmail.com" <ga...@gmail.com>.

On 2017-11-30 23:07, Matt Sicker <bo...@gmail.com> wrote: 
> You should be able to create one the same way you create any other appender
> using programmatic configuration.
> 
> On 30 November 2017 at 06:36, gaurav9822@gmail.com <ga...@gmail.com>
> wrote:
> 
> > Hi log4j2 users,
> >
> > I want to create jdbc appender using programmatic configuration.
> >
> > Please provide the programmatic configuration if you already have or guide
> > me to create it.
> >
> > P.S. I am able to create JDBCAppender using xml configuration
> >
> > Thanks
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>
> Hi Matt,

I am able to add "tableName" attribute for JDBC AppenderComponentBuilder
But not the remaining stuff like 
ConnectionFactory class,method and Columns.

Please help


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: How do I create jdbc appender using programmatic configuration?

Posted by Matt Sicker <bo...@gmail.com>.
You should be able to create one the same way you create any other appender
using programmatic configuration.

On 30 November 2017 at 06:36, gaurav9822@gmail.com <ga...@gmail.com>
wrote:

> Hi log4j2 users,
>
> I want to create jdbc appender using programmatic configuration.
>
> Please provide the programmatic configuration if you already have or guide
> me to create it.
>
> P.S. I am able to create JDBCAppender using xml configuration
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Matt Sicker <bo...@gmail.com>