logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Shaw <j...@bitgladiator.com>
Subject Re: How to make a custom connection source available in log4j 2 config?
Date Thu, 17 Apr 2014 01:31:26 GMT
Hi Ralph,
Thanks for your suggestions. I will try them. I am indeed using 2.0-rc1.

Jeff

On Wed, Apr 16, 2014 at 5:58 PM, Ralph Goers <ralph.goers@dslextreme.com> wrote:
> If you are using 2.0-rc1 then you need to make sure that you either:
> a) have the packages attribute specified on the configuration element with the correct
package name of your plugin.
> b) have run the PluginManager against your plugin and included the file it generated
in your jar.
>
> An enhancement was recently added to trunk that cause the plugin file to be generated
by an annotation processor that is invoked during the compile, making it easier for plugins
to be located automatically.
>
> Ralph
>
> On Apr 16, 2014, at 12:55 PM, Jeff Shaw <jeff@bitgladiator.com> wrote:
>
>> Hello,
>> I made a custom connection source that I want to use. (Source follows
>> this message.) However, when I attempt to use my BoneCP connection
>> source in my config, I get the error, "ERROR JDBC contains an invalid
>> element or attribute "BoneCP"". What else do I need to do to make my
>> custom connection source available in the configuration?
>>
>> I'm hoping the answer will also apply to a custom appender and manager
>> I've written, neither of which work because they also cannot be
>> instantiated from the configuration, however the error is a class not
>> found error.
>>
>> Thanks,
>> Jeff
>>
>> Source:
>>
>> /**
>> * Copyright (c) Bit Gladiator on 2014.
>> */
>>
>> @Plugin(name = "BoneCP", category="Core", elementType =
>> "connectionSource", printObject = true)
>> public class BoneCPConnectionSource implements ConnectionSource {
>>  private static final Logger LOGGER = StatusLogger.getLogger();
>>
>>  private final BoneCP pool;
>>
>>  private BoneCPConnectionSource(final BoneCP pool) {
>>    this.pool = pool;
>>  }
>>
>>  @PluginFactory
>>  public static BoneCPConnectionSource createConnectionSource(
>>    @PluginAttribute("url") final String url,
>>    @PluginAttribute("username") final String username,
>>    @PluginAttribute("password") final String password,
>>    @PluginAttribute("partitionCount") final String partitionCount,
>>    @PluginAttribute("connectionsPerPartition") final String
>> connectionsPerPartition
>>  ) {
>>    BoneCPConfig config = new BoneCPConfig();
>>    config.setJdbcUrl(url);
>>    config.setUsername(username);
>>    config.setPassword(password);
>>    config.setPartitionCount(Integer.parseInt(partitionCount));
>>    config.setMaxConnectionsPerPartition(Integer.parseInt(connectionsPerPartition));
>>    try {
>>      BoneCP pool = new BoneCP(config);
>>      return new BoneCPConnectionSource(pool);
>>    } catch (SQLException e) {
>>      LOGGER.error("Failed to create the connection pool.");
>>      return null;
>>    }
>>  }
>>
>>  @Override
>>  public Connection getConnection() throws SQLException {
>>    return pool.getConnection();
>>  }
>>
>>  @Override
>>  public String toString() {
>>    return pool.getConfig().toString();
>>  }
>> }
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Mime
View raw message