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

2017-12-01 Thread Matt Sicker
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, gaurav9...@gmail.com 
wrote:

>
>
> On 2017-12-01 14:34, "gaurav9...@gmail.com" wrote:
> >
> >
> > On 2017-11-30 23:07, Matt Sicker  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, gaurav9...@gmail.com <
> gaurav9...@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-unsubscr...@logging.apache.org
> > > > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> > > >
> > > >
> > >
> > >
> > > --
> > > Matt Sicker 
> > > 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-unsubscr...@logging.apache.org
> > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >
> > What I've tried until now:
>
>
> ConfigurationBuilder 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-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


-- 
Matt Sicker 


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

2017-12-01 Thread gaurav9...@gmail.com


On 2017-12-01 14:34, "gaurav9...@gmail.com" wrote: 
> 
> 
> On 2017-11-30 23:07, Matt Sicker  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, gaurav9...@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-unsubscr...@logging.apache.org
> > > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> > >
> > >
> > 
> > 
> > -- 
> > Matt Sicker 
> > 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-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 
> What I've tried until now:


ConfigurationBuilder 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-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



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

2017-12-01 Thread gaurav9...@gmail.com


On 2017-11-30 23:07, Matt Sicker  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, gaurav9...@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-unsubscr...@logging.apache.org
> > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >
> >
> 
> 
> -- 
> Matt Sicker 
> 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-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



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

2017-11-30 Thread Matt Sicker
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, gaurav9...@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-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


-- 
Matt Sicker