Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1864

Support capped collection for MongoDB Log-Provider

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.9.0
    • Component/s: Appenders
    • Labels:
      None

      Description

      MongoDB supports sth. called capped collections. If the nosql-mongodb-appender supports this feature, the mongodb-collection could never "overflow" and stick to a defined maximum size.

      see pull request 62 for more details.

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          Hi @jvz, Thanks that you're interested in this feature.
          I added a `feature request` to [jira](https://issues.apache.org/jira/browse/LOG4J2-1864). And I will take a look at your remarks as soon as possible. Cheers

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on the issue: https://github.com/apache/logging-log4j2/pull/62 Hi @jvz, Thanks that you're interested in this feature. I added a `feature request` to [jira] ( https://issues.apache.org/jira/browse/LOG4J2-1864 ). And I will take a look at your remarks as soon as possible. Cheers
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r109365941

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -97,6 +103,8 @@ public String toString() {
          @PluginFactory
          public static MongoDbProvider createNoSqlProvider(
          @PluginAttribute("collectionName") final String collectionName,
          + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped,
          — End diff –

          Hi @jvz, I changed the `Boolean` member to be a primitive type. But I don't know what kind of Builder you mean for the attributes? Does this builder exist for the MongoDbProvider? Cheers Matt

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r109365941 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -97,6 +103,8 @@ public String toString() { @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped, — End diff – Hi @jvz, I changed the `Boolean` member to be a primitive type. But I don't know what kind of Builder you mean for the attributes? Does this builder exist for the MongoDbProvider? Cheers Matt
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r109425995

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -97,6 +103,8 @@ public String toString() {
          @PluginFactory
          public static MongoDbProvider createNoSqlProvider(
          @PluginAttribute("collectionName") final String collectionName,
          + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped,
          — End diff –

          Take a look at CassandraAppender for how to write a plugin builder class. Any manual type conversion in the factory method can be generally updated to use the proper types as conversions for most common types is supported (and new types can always be added as appropriate; see InetAddress et al. added for CassandraAppender).

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r109425995 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -97,6 +103,8 @@ public String toString() { @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped, — End diff – Take a look at CassandraAppender for how to write a plugin builder class. Any manual type conversion in the factory method can be generally updated to use the proper types as conversions for most common types is supported (and new types can always be added as appropriate; see InetAddress et al. added for CassandraAppender).
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r110581005

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -97,6 +103,8 @@ public String toString() {
          @PluginFactory
          public static MongoDbProvider createNoSqlProvider(
          @PluginAttribute("collectionName") final String collectionName,
          + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped,
          — End diff –

          I took a look at the CassandraAppender. It's not a big deal to adjust the MongoDbProvider to match this style. But the API is also broken. Or do you intend to keep the old public methods? Shouldn't this even be another issues and pull-request?

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r110581005 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -97,6 +103,8 @@ public String toString() { @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped, — End diff – I took a look at the CassandraAppender. It's not a big deal to adjust the MongoDbProvider to match this style. But the API is also broken. Or do you intend to keep the old public methods? Shouldn't this even be another issues and pull-request?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r110666194

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -97,6 +103,8 @@ public String toString() {
          @PluginFactory
          public static MongoDbProvider createNoSqlProvider(
          @PluginAttribute("collectionName") final String collectionName,
          + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped,
          — End diff –

          What we've been doing with old factory methods is removing the annotations from them and marking them deprecated. That way it doesn't break custom configurations, but only the new builder is used for normal configuration (although builders are used before factory methods regardless).

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r110666194 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -97,6 +103,8 @@ public String toString() { @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, + @PluginAttribute(value = "capped", defaultBoolean = false) final Boolean isCapped, — End diff – What we've been doing with old factory methods is removing the annotations from them and marking them deprecated. That way it doesn't break custom configurations, but only the new builder is used for normal configuration (although builders are used before factory methods regardless).
          Hide
          garydgregory Gary Gregory added a comment -

          The old factory method does not come into play if you remove its annotation, which is what I have done in the past when adding a builder.

          Show
          garydgregory Gary Gregory added a comment - The old factory method does not come into play if you remove its annotation, which is what I have done in the past when adding a builder.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          I updated the `MongoDbProvider` how I understood you want it. But it's not working. Maybe you know why @jvz ?

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on the issue: https://github.com/apache/logging-log4j2/pull/62 I updated the `MongoDbProvider` how I understood you want it. But it's not working. Maybe you know why @jvz ?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          It looks correct based on a quick look, so I'm not sure what exactly is incorrect. I would like to note that the builders generally use the parsed type rather than a string, though I can help clean that up afterward.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on the issue: https://github.com/apache/logging-log4j2/pull/62 It looks correct based on a quick look, so I'm not sure what exactly is incorrect. I would like to note that the builders generally use the parsed type rather than a string, though I can help clean that up afterward.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          Fixed the problem. I extended from the wrong `Builder`. Please review and let me know if it's ok. Thx.

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on the issue: https://github.com/apache/logging-log4j2/pull/62 Fixed the problem. I extended from the wrong `Builder`. Please review and let me know if it's ok. Thx.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mikaelstaldal commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          Ping @jvz

          Show
          githubbot ASF GitHub Bot added a comment - Github user mikaelstaldal commented on the issue: https://github.com/apache/logging-log4j2/pull/62 Ping @jvz
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126477831

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -93,130 +103,249 @@ public String toString() {

          • @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
          • class.
          • @return a new MongoDB provider.
            + * @deprecated in 2.8; use {@link #newBuilder()}

            instead.
            */
            @PluginFactory
            public static MongoDbProvider createNoSqlProvider(

          • @PluginAttribute("collectionName") final String collectionName,
          • @PluginAttribute("writeConcernConstant") final String writeConcernConstant,
          • @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName,
          • @PluginAttribute("databaseName") final String databaseName,
          • @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server,
          • @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port,
          • @PluginAttribute("userName") final String userName,
          • @PluginAttribute(value = "password", sensitive = true) final String password,
          • @PluginAttribute("factoryClassName") final String factoryClassName,
          • @PluginAttribute("factoryMethodName") final String factoryMethodName) {
          • DB database;
          • String description;
          • if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
          • try {
          • final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
          • final Method method = factoryClass.getMethod(factoryMethodName);
          • final Object object = method.invoke(null);
            -
          • if (object instanceof DB) { - database = (DB) object; - }

            else if (object instanceof MongoClient) {

          • if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - }

            else {

          • LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
          • + "required.", factoryClassName, factoryMethodName);
          • return null;
          • }
          • } else if (object == null) {
          • LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
          • return null;
          • } else {
          • LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
          • factoryMethodName, object.getClass().getName());
          • return null;
          • }
            -
          • description = "database=" + database.getName();
          • final List<ServerAddress> addresses = database.getMongo().getAllAddress();
          • if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - }

            else {

          • description += ", servers=[";
          • for (final ServerAddress address : addresses) {
          • description += " { " + address.getHost() + ", " + address.getPort() + " }

            ";

          • }
          • description += "]";
          • }
          • } catch (final ClassNotFoundException e) {
          • LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
          • return null;
          • } catch (final NoSuchMethodException e) {
          • LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
          • factoryMethodName, e);
          • return null;
          • } catch (final Exception e) {
          • LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
          • e);
          • return null;
          • }
          • } else if (Strings.isNotEmpty(databaseName)) {
          • final List<MongoCredential> credentials = new ArrayList<>();
          • description = "database=" + databaseName;
          • if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - }
          • try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - }

            catch (final Exception e) {

          • LOGGER.error(
          • "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
          • server, port);
          • return null;
          • }
          • } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - }

            -

          • try { - database.getCollectionNames(); // Check if the database actually requires authentication - }

            catch (final Exception e)

            { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - }

            -

          • final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
            -
          • return new MongoDbProvider(database, writeConcern, collectionName, description);
          • }
            + final String collectionName,
            + final String writeConcernConstant,
            + final String writeConcernConstantClassName,
            + final String databaseName,
            + final String server,
            + final String port,
            + final String userName,
            + final String password,
            + final String factoryClassName,
            + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + }

            +
            + @PluginBuilderFactory
            + public static <B extends Builder<B>> B newBuilder()

            { + return new Builder<B>().asBuilder(); + }

            +
            + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
            + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
            +
            + @PluginBuilderAttribute
            + @ValidHost
            + private String server = "localhost";
            +
            + @PluginBuilderAttribute
            + @ValidPort
            + private String port = "" + DEFAULT_PORT;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No database name provided")
            + private String databaseName;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No collection name provided")
            + private String collectionName;
            +
            + @PluginBuilderAttribute
            + private String userName;
            +
            + @PluginBuilderAttribute(sensitive = true)
            + private String password;
            +
            + @PluginBuilderAttribute("capped")
            + private boolean isCapped = false;
            +
            + @PluginBuilderAttribute
            + private int collectionSize = DEFAULT_COLLECTION_SIZE;
            +
            + @PluginBuilderAttribute
            + private String factoryClassName;
            +
            + @PluginBuilderAttribute
            + private String factoryMethodName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstantClassName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstant;
            +
            + public B setServer(String server)

            { + this.server = server; + return asBuilder(); + }

            +
            + public B setPort(String port)

            { + this.port = port; + return asBuilder(); + }

            +
            + public B setDatabaseName(String databaseName)

            { + this.databaseName = databaseName; + return asBuilder(); + }

            +
            + public B setCollectionName(String collectionName)

            { + this.collectionName = collectionName; + return asBuilder(); + }

            +
            + public B setUserName(String userName)

            { + this.userName = userName; + return asBuilder(); + }

            +
            + public B setPassword(String password)

            { + this.password = password; + return asBuilder(); + }

            +
            + public B setCapped(boolean isCapped)

            { + this.isCapped = isCapped; + return asBuilder(); + }

            +
            + public B setCollectionSize(int collectionSize)

            { + this.collectionSize = collectionSize; + return asBuilder(); + }

            +
            + public B setFactoryClassName(String factoryClassName)

            { + this.factoryClassName = factoryClassName; + return asBuilder(); + }

            +
            + public B setFactoryMethodName(String factoryMethodName)

            { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + }

            +
            + public B setWriteConcernConstantClassName(String writeConcernConstantClassName)

            { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + }

            +
            + public B setWriteConcernConstant(String writeConcernConstant)

            { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + }

            +
            + @Override
            + public MongoDbProvider build() {
            + DB database;
            + String description;

              • End diff –

          It's not a huge deal performance-wise, but you could use a StringBuilder here for the more advanced concatenation. I doubt javac can optimize it like it does with other string concatenations.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126477831 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -93,130 +103,249 @@ public String toString() { @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory class. @return a new MongoDB provider. + * @deprecated in 2.8; use {@link #newBuilder()} instead. */ @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, @PluginAttribute("writeConcernConstant") final String writeConcernConstant, @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName, @PluginAttribute("databaseName") final String databaseName, @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server, @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port, @PluginAttribute("userName") final String userName, @PluginAttribute(value = "password", sensitive = true) final String password, @PluginAttribute("factoryClassName") final String factoryClassName, @PluginAttribute("factoryMethodName") final String factoryMethodName) { DB database; String description; if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { try { final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); final Method method = factoryClass.getMethod(factoryMethodName); final Object object = method.invoke(null); - if (object instanceof DB) { - database = (DB) object; - } else if (object instanceof MongoClient) { if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - } else { LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + "required.", factoryClassName, factoryMethodName); return null; } } else if (object == null) { LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); return null; } else { LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, factoryMethodName, object.getClass().getName()); return null; } - description = "database=" + database.getName(); final List<ServerAddress> addresses = database.getMongo().getAllAddress(); if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - } else { description += ", servers=["; for (final ServerAddress address : addresses) { description += " { " + address.getHost() + ", " + address.getPort() + " } "; } description += "]"; } } catch (final ClassNotFoundException e) { LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); return null; } catch (final NoSuchMethodException e) { LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, factoryMethodName, e); return null; } catch (final Exception e) { LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, e); return null; } } else if (Strings.isNotEmpty(databaseName)) { final List<MongoCredential> credentials = new ArrayList<>(); description = "database=" + databaseName; if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - } try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) { LOGGER.error( "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}] .", server, port); return null; } } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - } - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - } - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName); - return new MongoDbProvider(database, writeConcern, collectionName, description); } + final String collectionName, + final String writeConcernConstant, + final String writeConcernConstantClassName, + final String databaseName, + final String server, + final String port, + final String userName, + final String password, + final String factoryClassName, + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + } + + @PluginBuilderFactory + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + } + + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B> + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> { + + @PluginBuilderAttribute + @ValidHost + private String server = "localhost"; + + @PluginBuilderAttribute + @ValidPort + private String port = "" + DEFAULT_PORT; + + @PluginBuilderAttribute + @Required(message = "No database name provided") + private String databaseName; + + @PluginBuilderAttribute + @Required(message = "No collection name provided") + private String collectionName; + + @PluginBuilderAttribute + private String userName; + + @PluginBuilderAttribute(sensitive = true) + private String password; + + @PluginBuilderAttribute("capped") + private boolean isCapped = false; + + @PluginBuilderAttribute + private int collectionSize = DEFAULT_COLLECTION_SIZE; + + @PluginBuilderAttribute + private String factoryClassName; + + @PluginBuilderAttribute + private String factoryMethodName; + + @PluginBuilderAttribute + private String writeConcernConstantClassName; + + @PluginBuilderAttribute + private String writeConcernConstant; + + public B setServer(String server) { + this.server = server; + return asBuilder(); + } + + public B setPort(String port) { + this.port = port; + return asBuilder(); + } + + public B setDatabaseName(String databaseName) { + this.databaseName = databaseName; + return asBuilder(); + } + + public B setCollectionName(String collectionName) { + this.collectionName = collectionName; + return asBuilder(); + } + + public B setUserName(String userName) { + this.userName = userName; + return asBuilder(); + } + + public B setPassword(String password) { + this.password = password; + return asBuilder(); + } + + public B setCapped(boolean isCapped) { + this.isCapped = isCapped; + return asBuilder(); + } + + public B setCollectionSize(int collectionSize) { + this.collectionSize = collectionSize; + return asBuilder(); + } + + public B setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + return asBuilder(); + } + + public B setFactoryMethodName(String factoryMethodName) { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + } + + public B setWriteConcernConstantClassName(String writeConcernConstantClassName) { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + } + + public B setWriteConcernConstant(String writeConcernConstant) { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + } + + @Override + public MongoDbProvider build() { + DB database; + String description; End diff – It's not a huge deal performance-wise, but you could use a StringBuilder here for the more advanced concatenation. I doubt javac can optimize it like it does with other string concatenations.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126476842

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -93,130 +103,249 @@ public String toString() {

          • @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
          • class.
          • @return a new MongoDB provider.
            + * @deprecated in 2.8; use {@link #newBuilder()}

            instead.
            */
            @PluginFactory
            public static MongoDbProvider createNoSqlProvider(

          • @PluginAttribute("collectionName") final String collectionName,
          • @PluginAttribute("writeConcernConstant") final String writeConcernConstant,
          • @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName,
          • @PluginAttribute("databaseName") final String databaseName,
          • @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server,
          • @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port,
          • @PluginAttribute("userName") final String userName,
          • @PluginAttribute(value = "password", sensitive = true) final String password,
          • @PluginAttribute("factoryClassName") final String factoryClassName,
          • @PluginAttribute("factoryMethodName") final String factoryMethodName) {
          • DB database;
          • String description;
          • if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
          • try {
          • final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
          • final Method method = factoryClass.getMethod(factoryMethodName);
          • final Object object = method.invoke(null);
            -
          • if (object instanceof DB) { - database = (DB) object; - }

            else if (object instanceof MongoClient) {

          • if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - }

            else {

          • LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
          • + "required.", factoryClassName, factoryMethodName);
          • return null;
          • }
          • } else if (object == null) {
          • LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
          • return null;
          • } else {
          • LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
          • factoryMethodName, object.getClass().getName());
          • return null;
          • }
            -
          • description = "database=" + database.getName();
          • final List<ServerAddress> addresses = database.getMongo().getAllAddress();
          • if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - }

            else {

          • description += ", servers=[";
          • for (final ServerAddress address : addresses) {
          • description += " { " + address.getHost() + ", " + address.getPort() + " }

            ";

          • }
          • description += "]";
          • }
          • } catch (final ClassNotFoundException e) {
          • LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
          • return null;
          • } catch (final NoSuchMethodException e) {
          • LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
          • factoryMethodName, e);
          • return null;
          • } catch (final Exception e) {
          • LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
          • e);
          • return null;
          • }
          • } else if (Strings.isNotEmpty(databaseName)) {
          • final List<MongoCredential> credentials = new ArrayList<>();
          • description = "database=" + databaseName;
          • if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - }
          • try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - }

            catch (final Exception e) {

          • LOGGER.error(
          • "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
          • server, port);
          • return null;
          • }
          • } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - }

            -

          • try { - database.getCollectionNames(); // Check if the database actually requires authentication - }

            catch (final Exception e)

            { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - }

            -

          • final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
            -
          • return new MongoDbProvider(database, writeConcern, collectionName, description);
          • }
            + final String collectionName,
            + final String writeConcernConstant,
            + final String writeConcernConstantClassName,
            + final String databaseName,
            + final String server,
            + final String port,
            + final String userName,
            + final String password,
            + final String factoryClassName,
            + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + }

            +
            + @PluginBuilderFactory
            + public static <B extends Builder<B>> B newBuilder()

            { + return new Builder<B>().asBuilder(); + }

            +
            + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
            + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
            +
            + @PluginBuilderAttribute
            + @ValidHost
            + private String server = "localhost";
            +
            + @PluginBuilderAttribute
            + @ValidPort
            + private String port = "" + DEFAULT_PORT;

              • End diff –

          You can make this an int.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126476842 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -93,130 +103,249 @@ public String toString() { @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory class. @return a new MongoDB provider. + * @deprecated in 2.8; use {@link #newBuilder()} instead. */ @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, @PluginAttribute("writeConcernConstant") final String writeConcernConstant, @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName, @PluginAttribute("databaseName") final String databaseName, @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server, @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port, @PluginAttribute("userName") final String userName, @PluginAttribute(value = "password", sensitive = true) final String password, @PluginAttribute("factoryClassName") final String factoryClassName, @PluginAttribute("factoryMethodName") final String factoryMethodName) { DB database; String description; if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { try { final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); final Method method = factoryClass.getMethod(factoryMethodName); final Object object = method.invoke(null); - if (object instanceof DB) { - database = (DB) object; - } else if (object instanceof MongoClient) { if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - } else { LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + "required.", factoryClassName, factoryMethodName); return null; } } else if (object == null) { LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); return null; } else { LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, factoryMethodName, object.getClass().getName()); return null; } - description = "database=" + database.getName(); final List<ServerAddress> addresses = database.getMongo().getAllAddress(); if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - } else { description += ", servers=["; for (final ServerAddress address : addresses) { description += " { " + address.getHost() + ", " + address.getPort() + " } "; } description += "]"; } } catch (final ClassNotFoundException e) { LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); return null; } catch (final NoSuchMethodException e) { LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, factoryMethodName, e); return null; } catch (final Exception e) { LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, e); return null; } } else if (Strings.isNotEmpty(databaseName)) { final List<MongoCredential> credentials = new ArrayList<>(); description = "database=" + databaseName; if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - } try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) { LOGGER.error( "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}] .", server, port); return null; } } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - } - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - } - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName); - return new MongoDbProvider(database, writeConcern, collectionName, description); } + final String collectionName, + final String writeConcernConstant, + final String writeConcernConstantClassName, + final String databaseName, + final String server, + final String port, + final String userName, + final String password, + final String factoryClassName, + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + } + + @PluginBuilderFactory + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + } + + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B> + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> { + + @PluginBuilderAttribute + @ValidHost + private String server = "localhost"; + + @PluginBuilderAttribute + @ValidPort + private String port = "" + DEFAULT_PORT; End diff – You can make this an int.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126476697

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -21,50 +21,60 @@
          import java.util.ArrayList;
          import java.util.List;

          -import com.mongodb.DB;
          -import com.mongodb.MongoClient;
          -import com.mongodb.MongoCredential;
          -import com.mongodb.ServerAddress;
          -import com.mongodb.WriteConcern;
          import org.apache.logging.log4j.Logger;
          +import org.apache.logging.log4j.core.Core;
          import org.apache.logging.log4j.core.config.plugins.Plugin;
          -import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
          +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
          +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
          import org.apache.logging.log4j.core.config.plugins.PluginFactory;
          import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters;
          +import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
          import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidHost;
          import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidPort;
          +import org.apache.logging.log4j.core.filter.AbstractFilterable;
          import org.apache.logging.log4j.core.util.NameUtil;
          import org.apache.logging.log4j.nosql.appender.NoSqlProvider;
          import org.apache.logging.log4j.status.StatusLogger;
          import org.apache.logging.log4j.util.LoaderUtil;
          import org.apache.logging.log4j.util.Strings;

          +import com.mongodb.DB;
          +import com.mongodb.MongoClient;
          +import com.mongodb.MongoCredential;
          +import com.mongodb.ServerAddress;
          +import com.mongodb.WriteConcern;
          +
          /**

          • The MongoDB implementation of {@link NoSqlProvider}

            .
            */
            -@Plugin(name = "MongoDb", category = "Core", printObject = true)
            +@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
            public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> {

          private static final WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED;
          private static final Logger LOGGER = StatusLogger.getLogger();
          private static final int DEFAULT_PORT = 27017;
          + private static final int DEFAULT_COLLECTION_SIZE = 536870912;
          — End diff –

          Magic number?

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126476697 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -21,50 +21,60 @@ import java.util.ArrayList; import java.util.List; -import com.mongodb.DB; -import com.mongodb.MongoClient; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; -import com.mongodb.WriteConcern; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters; +import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidHost; import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidPort; +import org.apache.logging.log4j.core.filter.AbstractFilterable; import org.apache.logging.log4j.core.util.NameUtil; import org.apache.logging.log4j.nosql.appender.NoSqlProvider; import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.LoaderUtil; import org.apache.logging.log4j.util.Strings; +import com.mongodb.DB; +import com.mongodb.MongoClient; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.WriteConcern; + /** The MongoDB implementation of {@link NoSqlProvider} . */ -@Plugin(name = "MongoDb", category = "Core", printObject = true) +@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true) public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> { private static final WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED; private static final Logger LOGGER = StatusLogger.getLogger(); private static final int DEFAULT_PORT = 27017; + private static final int DEFAULT_COLLECTION_SIZE = 536870912; — End diff – Magic number?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126478075

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -93,130 +103,249 @@ public String toString() {

          • @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
          • class.
          • @return a new MongoDB provider.
            + * @deprecated in 2.8; use {@link #newBuilder()}

            instead.
            */
            @PluginFactory
            public static MongoDbProvider createNoSqlProvider(

          • @PluginAttribute("collectionName") final String collectionName,
          • @PluginAttribute("writeConcernConstant") final String writeConcernConstant,
          • @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName,
          • @PluginAttribute("databaseName") final String databaseName,
          • @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server,
          • @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port,
          • @PluginAttribute("userName") final String userName,
          • @PluginAttribute(value = "password", sensitive = true) final String password,
          • @PluginAttribute("factoryClassName") final String factoryClassName,
          • @PluginAttribute("factoryMethodName") final String factoryMethodName) {
          • DB database;
          • String description;
          • if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
          • try {
          • final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
          • final Method method = factoryClass.getMethod(factoryMethodName);
          • final Object object = method.invoke(null);
            -
          • if (object instanceof DB) { - database = (DB) object; - }

            else if (object instanceof MongoClient) {

          • if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - }

            else {

          • LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
          • + "required.", factoryClassName, factoryMethodName);
          • return null;
          • }
          • } else if (object == null) {
          • LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
          • return null;
          • } else {
          • LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
          • factoryMethodName, object.getClass().getName());
          • return null;
          • }
            -
          • description = "database=" + database.getName();
          • final List<ServerAddress> addresses = database.getMongo().getAllAddress();
          • if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - }

            else {

          • description += ", servers=[";
          • for (final ServerAddress address : addresses) {
          • description += " { " + address.getHost() + ", " + address.getPort() + " } ";
            - }
            - description += "]";
            - }
            - } catch (final ClassNotFoundException e) {
            - LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
            - return null;
            - } catch (final NoSuchMethodException e) {
            - LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
            - factoryMethodName, e);
            - return null;
            - } catch (final Exception e) {
            - LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
            - e);
            - return null;
            - }
            - } else if (Strings.isNotEmpty(databaseName)) {
            - final List<MongoCredential> credentials = new ArrayList<>();
            - description = "database=" + databaseName;
            - if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - }
            - try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) {
            - LOGGER.error(
            - "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
            - server, port);
            - return null;
            - }
            - } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - }
            -
            - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - }
            -
            - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
            -
            - return new MongoDbProvider(database, writeConcern, collectionName, description);
            - }
            + final String collectionName,
            + final String writeConcernConstant,
            + final String writeConcernConstantClassName,
            + final String databaseName,
            + final String server,
            + final String port,
            + final String userName,
            + final String password,
            + final String factoryClassName,
            + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + }
            +
            + @PluginBuilderFactory
            + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + }
            +
            + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
            + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
            +
            + @PluginBuilderAttribute
            + @ValidHost
            + private String server = "localhost";
            +
            + @PluginBuilderAttribute
            + @ValidPort
            + private String port = "" + DEFAULT_PORT;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No database name provided")
            + private String databaseName;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No collection name provided")
            + private String collectionName;
            +
            + @PluginBuilderAttribute
            + private String userName;
            +
            + @PluginBuilderAttribute(sensitive = true)
            + private String password;
            +
            + @PluginBuilderAttribute("capped")
            + private boolean isCapped = false;
            +
            + @PluginBuilderAttribute
            + private int collectionSize = DEFAULT_COLLECTION_SIZE;
            +
            + @PluginBuilderAttribute
            + private String factoryClassName;
            +
            + @PluginBuilderAttribute
            + private String factoryMethodName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstantClassName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstant;
            +
            + public B setServer(String server) { + this.server = server; + return asBuilder(); + }
            +
            + public B setPort(String port) { + this.port = port; + return asBuilder(); + }
            +
            + public B setDatabaseName(String databaseName) { + this.databaseName = databaseName; + return asBuilder(); + }
            +
            + public B setCollectionName(String collectionName) { + this.collectionName = collectionName; + return asBuilder(); + }
            +
            + public B setUserName(String userName) { + this.userName = userName; + return asBuilder(); + }
            +
            + public B setPassword(String password) { + this.password = password; + return asBuilder(); + }
            +
            + public B setCapped(boolean isCapped) { + this.isCapped = isCapped; + return asBuilder(); + }
            +
            + public B setCollectionSize(int collectionSize) { + this.collectionSize = collectionSize; + return asBuilder(); + }
            +
            + public B setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + return asBuilder(); + }
            +
            + public B setFactoryMethodName(String factoryMethodName) { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + }
            +
            + public B setWriteConcernConstantClassName(String writeConcernConstantClassName) { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + }
            +
            + public B setWriteConcernConstant(String writeConcernConstant) { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + }
            +
            + @Override
            + public MongoDbProvider build() {
            + DB database;
            + String description;
            + if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
            + try {
            + final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
            + final Method method = factoryClass.getMethod(factoryMethodName);
            + final Object object = method.invoke(null);
            +
            + if (object instanceof DB) { + database = (DB) object; + } else if (object instanceof MongoClient) {
            + if (Strings.isNotEmpty(databaseName)) { + database = ((MongoClient) object).getDB(databaseName); + } else {
            + LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
            + + "required.", factoryClassName, factoryMethodName);
            + return null;
            + }
            + } else if (object == null) {
            + LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
            + return null;
            + } else {
            + LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
            + factoryMethodName, object.getClass().getName());
            + return null;
            + }
            +
            + description = "database=" + database.getName();
            + final List<ServerAddress> addresses = database.getMongo().getAllAddress();
            + if (addresses.size() == 1) { + description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); + } else {
            + description += ", servers=[";
            + for (final ServerAddress address : addresses) {
            + description += " { " + address.getHost() + ", " + address.getPort() + " }

            ";
            + }
            + description += "]";
            + }
            + } catch (final ClassNotFoundException e) {
            + LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
            + return null;
            + } catch (final NoSuchMethodException e) {
            + LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
            + factoryMethodName, e);
            + return null;
            + } catch (final Exception e) {
            + LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
            + e);
            + return null;
            + }
            + } else if (Strings.isNotEmpty(databaseName)) {
            + final List<MongoCredential> credentials = new ArrayList<>();
            + description = "database=" + databaseName;
            + if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password))

            { + description += ", username=" + userName + ", passwordHash=" + + NameUtil.md5(password + MongoDbProvider.class.getName()); + credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); + }

            + try {
            + final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT);

              • End diff –

          As mentioned elsewhere, if you make the field an int, you don't need to do this.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126478075 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -93,130 +103,249 @@ public String toString() { @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory class. @return a new MongoDB provider. + * @deprecated in 2.8; use {@link #newBuilder()} instead. */ @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, @PluginAttribute("writeConcernConstant") final String writeConcernConstant, @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName, @PluginAttribute("databaseName") final String databaseName, @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server, @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port, @PluginAttribute("userName") final String userName, @PluginAttribute(value = "password", sensitive = true) final String password, @PluginAttribute("factoryClassName") final String factoryClassName, @PluginAttribute("factoryMethodName") final String factoryMethodName) { DB database; String description; if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { try { final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); final Method method = factoryClass.getMethod(factoryMethodName); final Object object = method.invoke(null); - if (object instanceof DB) { - database = (DB) object; - } else if (object instanceof MongoClient) { if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - } else { LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + "required.", factoryClassName, factoryMethodName); return null; } } else if (object == null) { LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); return null; } else { LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, factoryMethodName, object.getClass().getName()); return null; } - description = "database=" + database.getName(); final List<ServerAddress> addresses = database.getMongo().getAllAddress(); if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - } else { description += ", servers=["; for (final ServerAddress address : addresses) { description += " { " + address.getHost() + ", " + address.getPort() + " } "; - } - description += "]"; - } - } catch (final ClassNotFoundException e) { - LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); - return null; - } catch (final NoSuchMethodException e) { - LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, - factoryMethodName, e); - return null; - } catch (final Exception e) { - LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, - e); - return null; - } - } else if (Strings.isNotEmpty(databaseName)) { - final List<MongoCredential> credentials = new ArrayList<>(); - description = "database=" + databaseName; - if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - } - try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) { - LOGGER.error( - "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}] .", - server, port); - return null; - } - } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - } - - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - } - - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName); - - return new MongoDbProvider(database, writeConcern, collectionName, description); - } + final String collectionName, + final String writeConcernConstant, + final String writeConcernConstantClassName, + final String databaseName, + final String server, + final String port, + final String userName, + final String password, + final String factoryClassName, + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + } + + @PluginBuilderFactory + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + } + + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B> + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> { + + @PluginBuilderAttribute + @ValidHost + private String server = "localhost"; + + @PluginBuilderAttribute + @ValidPort + private String port = "" + DEFAULT_PORT; + + @PluginBuilderAttribute + @Required(message = "No database name provided") + private String databaseName; + + @PluginBuilderAttribute + @Required(message = "No collection name provided") + private String collectionName; + + @PluginBuilderAttribute + private String userName; + + @PluginBuilderAttribute(sensitive = true) + private String password; + + @PluginBuilderAttribute("capped") + private boolean isCapped = false; + + @PluginBuilderAttribute + private int collectionSize = DEFAULT_COLLECTION_SIZE; + + @PluginBuilderAttribute + private String factoryClassName; + + @PluginBuilderAttribute + private String factoryMethodName; + + @PluginBuilderAttribute + private String writeConcernConstantClassName; + + @PluginBuilderAttribute + private String writeConcernConstant; + + public B setServer(String server) { + this.server = server; + return asBuilder(); + } + + public B setPort(String port) { + this.port = port; + return asBuilder(); + } + + public B setDatabaseName(String databaseName) { + this.databaseName = databaseName; + return asBuilder(); + } + + public B setCollectionName(String collectionName) { + this.collectionName = collectionName; + return asBuilder(); + } + + public B setUserName(String userName) { + this.userName = userName; + return asBuilder(); + } + + public B setPassword(String password) { + this.password = password; + return asBuilder(); + } + + public B setCapped(boolean isCapped) { + this.isCapped = isCapped; + return asBuilder(); + } + + public B setCollectionSize(int collectionSize) { + this.collectionSize = collectionSize; + return asBuilder(); + } + + public B setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + return asBuilder(); + } + + public B setFactoryMethodName(String factoryMethodName) { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + } + + public B setWriteConcernConstantClassName(String writeConcernConstantClassName) { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + } + + public B setWriteConcernConstant(String writeConcernConstant) { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + } + + @Override + public MongoDbProvider build() { + DB database; + String description; + if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { + try { + final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); + final Method method = factoryClass.getMethod(factoryMethodName); + final Object object = method.invoke(null); + + if (object instanceof DB) { + database = (DB) object; + } else if (object instanceof MongoClient) { + if (Strings.isNotEmpty(databaseName)) { + database = ((MongoClient) object).getDB(databaseName); + } else { + LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + + "required.", factoryClassName, factoryMethodName); + return null; + } + } else if (object == null) { + LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); + return null; + } else { + LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, + factoryMethodName, object.getClass().getName()); + return null; + } + + description = "database=" + database.getName(); + final List<ServerAddress> addresses = database.getMongo().getAllAddress(); + if (addresses.size() == 1) { + description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); + } else { + description += ", servers=["; + for (final ServerAddress address : addresses) { + description += " { " + address.getHost() + ", " + address.getPort() + " } "; + } + description += "]"; + } + } catch (final ClassNotFoundException e) { + LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); + return null; + } catch (final NoSuchMethodException e) { + LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, + factoryMethodName, e); + return null; + } catch (final Exception e) { + LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, + e); + return null; + } + } else if (Strings.isNotEmpty(databaseName)) { + final List<MongoCredential> credentials = new ArrayList<>(); + description = "database=" + databaseName; + if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { + description += ", username=" + userName + ", passwordHash=" + + NameUtil.md5(password + MongoDbProvider.class.getName()); + credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); + } + try { + final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); End diff – As mentioned elsewhere, if you make the field an int, you don't need to do this.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126504007

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -93,130 +103,249 @@ public String toString() {

          • @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
          • class.
          • @return a new MongoDB provider.
            + * @deprecated in 2.8; use {@link #newBuilder()}

            instead.
            */
            @PluginFactory
            public static MongoDbProvider createNoSqlProvider(

          • @PluginAttribute("collectionName") final String collectionName,
          • @PluginAttribute("writeConcernConstant") final String writeConcernConstant,
          • @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName,
          • @PluginAttribute("databaseName") final String databaseName,
          • @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server,
          • @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port,
          • @PluginAttribute("userName") final String userName,
          • @PluginAttribute(value = "password", sensitive = true) final String password,
          • @PluginAttribute("factoryClassName") final String factoryClassName,
          • @PluginAttribute("factoryMethodName") final String factoryMethodName) {
          • DB database;
          • String description;
          • if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
          • try {
          • final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
          • final Method method = factoryClass.getMethod(factoryMethodName);
          • final Object object = method.invoke(null);
            -
          • if (object instanceof DB) { - database = (DB) object; - }

            else if (object instanceof MongoClient) {

          • if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - }

            else {

          • LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
          • + "required.", factoryClassName, factoryMethodName);
          • return null;
          • }
          • } else if (object == null) {
          • LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
          • return null;
          • } else {
          • LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
          • factoryMethodName, object.getClass().getName());
          • return null;
          • }
            -
          • description = "database=" + database.getName();
          • final List<ServerAddress> addresses = database.getMongo().getAllAddress();
          • if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - }

            else {

          • description += ", servers=[";
          • for (final ServerAddress address : addresses) {
          • description += " { " + address.getHost() + ", " + address.getPort() + " } ";
            - }
            - description += "]";
            - }
            - } catch (final ClassNotFoundException e) {
            - LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
            - return null;
            - } catch (final NoSuchMethodException e) {
            - LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
            - factoryMethodName, e);
            - return null;
            - } catch (final Exception e) {
            - LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
            - e);
            - return null;
            - }
            - } else if (Strings.isNotEmpty(databaseName)) {
            - final List<MongoCredential> credentials = new ArrayList<>();
            - description = "database=" + databaseName;
            - if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - }
            - try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) {
            - LOGGER.error(
            - "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
            - server, port);
            - return null;
            - }
            - } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - }
            -
            - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - }
            -
            - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
            -
            - return new MongoDbProvider(database, writeConcern, collectionName, description);
            - }
            + final String collectionName,
            + final String writeConcernConstant,
            + final String writeConcernConstantClassName,
            + final String databaseName,
            + final String server,
            + final String port,
            + final String userName,
            + final String password,
            + final String factoryClassName,
            + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + }
            +
            + @PluginBuilderFactory
            + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + }
            +
            + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
            + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
            +
            + @PluginBuilderAttribute
            + @ValidHost
            + private String server = "localhost";
            +
            + @PluginBuilderAttribute
            + @ValidPort
            + private String port = "" + DEFAULT_PORT;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No database name provided")
            + private String databaseName;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No collection name provided")
            + private String collectionName;
            +
            + @PluginBuilderAttribute
            + private String userName;
            +
            + @PluginBuilderAttribute(sensitive = true)
            + private String password;
            +
            + @PluginBuilderAttribute("capped")
            + private boolean isCapped = false;
            +
            + @PluginBuilderAttribute
            + private int collectionSize = DEFAULT_COLLECTION_SIZE;
            +
            + @PluginBuilderAttribute
            + private String factoryClassName;
            +
            + @PluginBuilderAttribute
            + private String factoryMethodName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstantClassName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstant;
            +
            + public B setServer(String server) { + this.server = server; + return asBuilder(); + }
            +
            + public B setPort(String port) { + this.port = port; + return asBuilder(); + }
            +
            + public B setDatabaseName(String databaseName) { + this.databaseName = databaseName; + return asBuilder(); + }
            +
            + public B setCollectionName(String collectionName) { + this.collectionName = collectionName; + return asBuilder(); + }
            +
            + public B setUserName(String userName) { + this.userName = userName; + return asBuilder(); + }
            +
            + public B setPassword(String password) { + this.password = password; + return asBuilder(); + }
            +
            + public B setCapped(boolean isCapped) { + this.isCapped = isCapped; + return asBuilder(); + }
            +
            + public B setCollectionSize(int collectionSize) { + this.collectionSize = collectionSize; + return asBuilder(); + }
            +
            + public B setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + return asBuilder(); + }
            +
            + public B setFactoryMethodName(String factoryMethodName) { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + }
            +
            + public B setWriteConcernConstantClassName(String writeConcernConstantClassName) { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + }
            +
            + public B setWriteConcernConstant(String writeConcernConstant) { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + }
            +
            + @Override
            + public MongoDbProvider build() {
            + DB database;
            + String description;
            + if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
            + try {
            + final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
            + final Method method = factoryClass.getMethod(factoryMethodName);
            + final Object object = method.invoke(null);
            +
            + if (object instanceof DB) { + database = (DB) object; + } else if (object instanceof MongoClient) {
            + if (Strings.isNotEmpty(databaseName)) { + database = ((MongoClient) object).getDB(databaseName); + } else {
            + LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
            + + "required.", factoryClassName, factoryMethodName);
            + return null;
            + }
            + } else if (object == null) {
            + LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
            + return null;
            + } else {
            + LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
            + factoryMethodName, object.getClass().getName());
            + return null;
            + }
            +
            + description = "database=" + database.getName();
            + final List<ServerAddress> addresses = database.getMongo().getAllAddress();
            + if (addresses.size() == 1) { + description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); + } else {
            + description += ", servers=[";
            + for (final ServerAddress address : addresses) {
            + description += " { " + address.getHost() + ", " + address.getPort() + " }

            ";
            + }
            + description += "]";
            + }
            + } catch (final ClassNotFoundException e) {
            + LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
            + return null;
            + } catch (final NoSuchMethodException e) {
            + LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
            + factoryMethodName, e);
            + return null;
            + } catch (final Exception e) {
            + LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
            + e);
            + return null;
            + }
            + } else if (Strings.isNotEmpty(databaseName)) {
            + final List<MongoCredential> credentials = new ArrayList<>();
            + description = "database=" + databaseName;
            + if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password))

            { + description += ", username=" + userName + ", passwordHash=" + + NameUtil.md5(password + MongoDbProvider.class.getName()); + credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); + }

            + try {
            + final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT);

              • End diff –

          https://github.com/codescale/logging-log4j2/blob/master/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java#L296

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126504007 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -93,130 +103,249 @@ public String toString() { @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory class. @return a new MongoDB provider. + * @deprecated in 2.8; use {@link #newBuilder()} instead. */ @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, @PluginAttribute("writeConcernConstant") final String writeConcernConstant, @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName, @PluginAttribute("databaseName") final String databaseName, @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server, @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port, @PluginAttribute("userName") final String userName, @PluginAttribute(value = "password", sensitive = true) final String password, @PluginAttribute("factoryClassName") final String factoryClassName, @PluginAttribute("factoryMethodName") final String factoryMethodName) { DB database; String description; if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { try { final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); final Method method = factoryClass.getMethod(factoryMethodName); final Object object = method.invoke(null); - if (object instanceof DB) { - database = (DB) object; - } else if (object instanceof MongoClient) { if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - } else { LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + "required.", factoryClassName, factoryMethodName); return null; } } else if (object == null) { LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); return null; } else { LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, factoryMethodName, object.getClass().getName()); return null; } - description = "database=" + database.getName(); final List<ServerAddress> addresses = database.getMongo().getAllAddress(); if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - } else { description += ", servers=["; for (final ServerAddress address : addresses) { description += " { " + address.getHost() + ", " + address.getPort() + " } "; - } - description += "]"; - } - } catch (final ClassNotFoundException e) { - LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); - return null; - } catch (final NoSuchMethodException e) { - LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, - factoryMethodName, e); - return null; - } catch (final Exception e) { - LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, - e); - return null; - } - } else if (Strings.isNotEmpty(databaseName)) { - final List<MongoCredential> credentials = new ArrayList<>(); - description = "database=" + databaseName; - if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - } - try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) { - LOGGER.error( - "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}] .", - server, port); - return null; - } - } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - } - - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - } - - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName); - - return new MongoDbProvider(database, writeConcern, collectionName, description); - } + final String collectionName, + final String writeConcernConstant, + final String writeConcernConstantClassName, + final String databaseName, + final String server, + final String port, + final String userName, + final String password, + final String factoryClassName, + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + } + + @PluginBuilderFactory + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + } + + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B> + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> { + + @PluginBuilderAttribute + @ValidHost + private String server = "localhost"; + + @PluginBuilderAttribute + @ValidPort + private String port = "" + DEFAULT_PORT; + + @PluginBuilderAttribute + @Required(message = "No database name provided") + private String databaseName; + + @PluginBuilderAttribute + @Required(message = "No collection name provided") + private String collectionName; + + @PluginBuilderAttribute + private String userName; + + @PluginBuilderAttribute(sensitive = true) + private String password; + + @PluginBuilderAttribute("capped") + private boolean isCapped = false; + + @PluginBuilderAttribute + private int collectionSize = DEFAULT_COLLECTION_SIZE; + + @PluginBuilderAttribute + private String factoryClassName; + + @PluginBuilderAttribute + private String factoryMethodName; + + @PluginBuilderAttribute + private String writeConcernConstantClassName; + + @PluginBuilderAttribute + private String writeConcernConstant; + + public B setServer(String server) { + this.server = server; + return asBuilder(); + } + + public B setPort(String port) { + this.port = port; + return asBuilder(); + } + + public B setDatabaseName(String databaseName) { + this.databaseName = databaseName; + return asBuilder(); + } + + public B setCollectionName(String collectionName) { + this.collectionName = collectionName; + return asBuilder(); + } + + public B setUserName(String userName) { + this.userName = userName; + return asBuilder(); + } + + public B setPassword(String password) { + this.password = password; + return asBuilder(); + } + + public B setCapped(boolean isCapped) { + this.isCapped = isCapped; + return asBuilder(); + } + + public B setCollectionSize(int collectionSize) { + this.collectionSize = collectionSize; + return asBuilder(); + } + + public B setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + return asBuilder(); + } + + public B setFactoryMethodName(String factoryMethodName) { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + } + + public B setWriteConcernConstantClassName(String writeConcernConstantClassName) { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + } + + public B setWriteConcernConstant(String writeConcernConstant) { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + } + + @Override + public MongoDbProvider build() { + DB database; + String description; + if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { + try { + final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); + final Method method = factoryClass.getMethod(factoryMethodName); + final Object object = method.invoke(null); + + if (object instanceof DB) { + database = (DB) object; + } else if (object instanceof MongoClient) { + if (Strings.isNotEmpty(databaseName)) { + database = ((MongoClient) object).getDB(databaseName); + } else { + LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + + "required.", factoryClassName, factoryMethodName); + return null; + } + } else if (object == null) { + LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); + return null; + } else { + LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, + factoryMethodName, object.getClass().getName()); + return null; + } + + description = "database=" + database.getName(); + final List<ServerAddress> addresses = database.getMongo().getAllAddress(); + if (addresses.size() == 1) { + description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); + } else { + description += ", servers=["; + for (final ServerAddress address : addresses) { + description += " { " + address.getHost() + ", " + address.getPort() + " } "; + } + description += "]"; + } + } catch (final ClassNotFoundException e) { + LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); + return null; + } catch (final NoSuchMethodException e) { + LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, + factoryMethodName, e); + return null; + } catch (final Exception e) { + LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, + e); + return null; + } + } else if (Strings.isNotEmpty(databaseName)) { + final List<MongoCredential> credentials = new ArrayList<>(); + description = "database=" + databaseName; + if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { + description += ", username=" + userName + ", passwordHash=" + + NameUtil.md5(password + MongoDbProvider.class.getName()); + credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); + } + try { + final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); End diff – https://github.com/codescale/logging-log4j2/blob/master/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java#L296
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126504026

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -93,130 +103,249 @@ public String toString() {

          • @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
          • class.
          • @return a new MongoDB provider.
            + * @deprecated in 2.8; use {@link #newBuilder()}

            instead.
            */
            @PluginFactory
            public static MongoDbProvider createNoSqlProvider(

          • @PluginAttribute("collectionName") final String collectionName,
          • @PluginAttribute("writeConcernConstant") final String writeConcernConstant,
          • @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName,
          • @PluginAttribute("databaseName") final String databaseName,
          • @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server,
          • @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port,
          • @PluginAttribute("userName") final String userName,
          • @PluginAttribute(value = "password", sensitive = true) final String password,
          • @PluginAttribute("factoryClassName") final String factoryClassName,
          • @PluginAttribute("factoryMethodName") final String factoryMethodName) {
          • DB database;
          • String description;
          • if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
          • try {
          • final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
          • final Method method = factoryClass.getMethod(factoryMethodName);
          • final Object object = method.invoke(null);
            -
          • if (object instanceof DB) { - database = (DB) object; - }

            else if (object instanceof MongoClient) {

          • if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - }

            else {

          • LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
          • + "required.", factoryClassName, factoryMethodName);
          • return null;
          • }
          • } else if (object == null) {
          • LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
          • return null;
          • } else {
          • LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
          • factoryMethodName, object.getClass().getName());
          • return null;
          • }
            -
          • description = "database=" + database.getName();
          • final List<ServerAddress> addresses = database.getMongo().getAllAddress();
          • if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - }

            else {

          • description += ", servers=[";
          • for (final ServerAddress address : addresses) {
          • description += " { " + address.getHost() + ", " + address.getPort() + " }

            ";

          • }
          • description += "]";
          • }
          • } catch (final ClassNotFoundException e) {
          • LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
          • return null;
          • } catch (final NoSuchMethodException e) {
          • LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
          • factoryMethodName, e);
          • return null;
          • } catch (final Exception e) {
          • LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
          • e);
          • return null;
          • }
          • } else if (Strings.isNotEmpty(databaseName)) {
          • final List<MongoCredential> credentials = new ArrayList<>();
          • description = "database=" + databaseName;
          • if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - }
          • try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - }

            catch (final Exception e) {

          • LOGGER.error(
          • "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
          • server, port);
          • return null;
          • }
          • } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - }

            -

          • try { - database.getCollectionNames(); // Check if the database actually requires authentication - }

            catch (final Exception e)

            { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - }

            -

          • final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
            -
          • return new MongoDbProvider(database, writeConcern, collectionName, description);
          • }
            + final String collectionName,
            + final String writeConcernConstant,
            + final String writeConcernConstantClassName,
            + final String databaseName,
            + final String server,
            + final String port,
            + final String userName,
            + final String password,
            + final String factoryClassName,
            + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + }

            +
            + @PluginBuilderFactory
            + public static <B extends Builder<B>> B newBuilder()

            { + return new Builder<B>().asBuilder(); + }

            +
            + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
            + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
            +
            + @PluginBuilderAttribute
            + @ValidHost
            + private String server = "localhost";
            +
            + @PluginBuilderAttribute
            + @ValidPort
            + private String port = "" + DEFAULT_PORT;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No database name provided")
            + private String databaseName;
            +
            + @PluginBuilderAttribute
            + @Required(message = "No collection name provided")
            + private String collectionName;
            +
            + @PluginBuilderAttribute
            + private String userName;
            +
            + @PluginBuilderAttribute(sensitive = true)
            + private String password;
            +
            + @PluginBuilderAttribute("capped")
            + private boolean isCapped = false;
            +
            + @PluginBuilderAttribute
            + private int collectionSize = DEFAULT_COLLECTION_SIZE;
            +
            + @PluginBuilderAttribute
            + private String factoryClassName;
            +
            + @PluginBuilderAttribute
            + private String factoryMethodName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstantClassName;
            +
            + @PluginBuilderAttribute
            + private String writeConcernConstant;
            +
            + public B setServer(String server)

            { + this.server = server; + return asBuilder(); + }

            +
            + public B setPort(String port)

            { + this.port = port; + return asBuilder(); + }

            +
            + public B setDatabaseName(String databaseName)

            { + this.databaseName = databaseName; + return asBuilder(); + }

            +
            + public B setCollectionName(String collectionName)

            { + this.collectionName = collectionName; + return asBuilder(); + }

            +
            + public B setUserName(String userName)

            { + this.userName = userName; + return asBuilder(); + }

            +
            + public B setPassword(String password)

            { + this.password = password; + return asBuilder(); + }

            +
            + public B setCapped(boolean isCapped)

            { + this.isCapped = isCapped; + return asBuilder(); + }

            +
            + public B setCollectionSize(int collectionSize)

            { + this.collectionSize = collectionSize; + return asBuilder(); + }

            +
            + public B setFactoryClassName(String factoryClassName)

            { + this.factoryClassName = factoryClassName; + return asBuilder(); + }

            +
            + public B setFactoryMethodName(String factoryMethodName)

            { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + }

            +
            + public B setWriteConcernConstantClassName(String writeConcernConstantClassName)

            { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + }

            +
            + public B setWriteConcernConstant(String writeConcernConstant)

            { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + }

            +
            + @Override
            + public MongoDbProvider build() {
            + DB database;
            + String description;

              • End diff –

          Again ... no changes from my side.

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126504026 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -93,130 +103,249 @@ public String toString() { @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory class. @return a new MongoDB provider. + * @deprecated in 2.8; use {@link #newBuilder()} instead. */ @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, @PluginAttribute("writeConcernConstant") final String writeConcernConstant, @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName, @PluginAttribute("databaseName") final String databaseName, @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server, @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port, @PluginAttribute("userName") final String userName, @PluginAttribute(value = "password", sensitive = true) final String password, @PluginAttribute("factoryClassName") final String factoryClassName, @PluginAttribute("factoryMethodName") final String factoryMethodName) { DB database; String description; if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { try { final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); final Method method = factoryClass.getMethod(factoryMethodName); final Object object = method.invoke(null); - if (object instanceof DB) { - database = (DB) object; - } else if (object instanceof MongoClient) { if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - } else { LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + "required.", factoryClassName, factoryMethodName); return null; } } else if (object == null) { LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); return null; } else { LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, factoryMethodName, object.getClass().getName()); return null; } - description = "database=" + database.getName(); final List<ServerAddress> addresses = database.getMongo().getAllAddress(); if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - } else { description += ", servers=["; for (final ServerAddress address : addresses) { description += " { " + address.getHost() + ", " + address.getPort() + " } "; } description += "]"; } } catch (final ClassNotFoundException e) { LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); return null; } catch (final NoSuchMethodException e) { LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, factoryMethodName, e); return null; } catch (final Exception e) { LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, e); return null; } } else if (Strings.isNotEmpty(databaseName)) { final List<MongoCredential> credentials = new ArrayList<>(); description = "database=" + databaseName; if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - } try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) { LOGGER.error( "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}] .", server, port); return null; } } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - } - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - } - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName); - return new MongoDbProvider(database, writeConcern, collectionName, description); } + final String collectionName, + final String writeConcernConstant, + final String writeConcernConstantClassName, + final String databaseName, + final String server, + final String port, + final String userName, + final String password, + final String factoryClassName, + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + } + + @PluginBuilderFactory + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + } + + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B> + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> { + + @PluginBuilderAttribute + @ValidHost + private String server = "localhost"; + + @PluginBuilderAttribute + @ValidPort + private String port = "" + DEFAULT_PORT; + + @PluginBuilderAttribute + @Required(message = "No database name provided") + private String databaseName; + + @PluginBuilderAttribute + @Required(message = "No collection name provided") + private String collectionName; + + @PluginBuilderAttribute + private String userName; + + @PluginBuilderAttribute(sensitive = true) + private String password; + + @PluginBuilderAttribute("capped") + private boolean isCapped = false; + + @PluginBuilderAttribute + private int collectionSize = DEFAULT_COLLECTION_SIZE; + + @PluginBuilderAttribute + private String factoryClassName; + + @PluginBuilderAttribute + private String factoryMethodName; + + @PluginBuilderAttribute + private String writeConcernConstantClassName; + + @PluginBuilderAttribute + private String writeConcernConstant; + + public B setServer(String server) { + this.server = server; + return asBuilder(); + } + + public B setPort(String port) { + this.port = port; + return asBuilder(); + } + + public B setDatabaseName(String databaseName) { + this.databaseName = databaseName; + return asBuilder(); + } + + public B setCollectionName(String collectionName) { + this.collectionName = collectionName; + return asBuilder(); + } + + public B setUserName(String userName) { + this.userName = userName; + return asBuilder(); + } + + public B setPassword(String password) { + this.password = password; + return asBuilder(); + } + + public B setCapped(boolean isCapped) { + this.isCapped = isCapped; + return asBuilder(); + } + + public B setCollectionSize(int collectionSize) { + this.collectionSize = collectionSize; + return asBuilder(); + } + + public B setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + return asBuilder(); + } + + public B setFactoryMethodName(String factoryMethodName) { + this.factoryMethodName = factoryMethodName; + return asBuilder(); + } + + public B setWriteConcernConstantClassName(String writeConcernConstantClassName) { + this.writeConcernConstantClassName = writeConcernConstantClassName; + return asBuilder(); + } + + public B setWriteConcernConstant(String writeConcernConstant) { + this.writeConcernConstant = writeConcernConstant; + return asBuilder(); + } + + @Override + public MongoDbProvider build() { + DB database; + String description; End diff – Again ... no changes from my side.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126504038

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -93,130 +103,249 @@ public String toString() {

          • @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory
          • class.
          • @return a new MongoDB provider.
            + * @deprecated in 2.8; use {@link #newBuilder()}

            instead.
            */
            @PluginFactory
            public static MongoDbProvider createNoSqlProvider(

          • @PluginAttribute("collectionName") final String collectionName,
          • @PluginAttribute("writeConcernConstant") final String writeConcernConstant,
          • @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName,
          • @PluginAttribute("databaseName") final String databaseName,
          • @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server,
          • @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port,
          • @PluginAttribute("userName") final String userName,
          • @PluginAttribute(value = "password", sensitive = true) final String password,
          • @PluginAttribute("factoryClassName") final String factoryClassName,
          • @PluginAttribute("factoryMethodName") final String factoryMethodName) {
          • DB database;
          • String description;
          • if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) {
          • try {
          • final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName);
          • final Method method = factoryClass.getMethod(factoryMethodName);
          • final Object object = method.invoke(null);
            -
          • if (object instanceof DB) { - database = (DB) object; - }

            else if (object instanceof MongoClient) {

          • if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - }

            else {

          • LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
          • + "required.", factoryClassName, factoryMethodName);
          • return null;
          • }
          • } else if (object == null) {
          • LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
          • return null;
          • } else {
          • LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
          • factoryMethodName, object.getClass().getName());
          • return null;
          • }
            -
          • description = "database=" + database.getName();
          • final List<ServerAddress> addresses = database.getMongo().getAllAddress();
          • if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - }

            else {

          • description += ", servers=[";
          • for (final ServerAddress address : addresses) {
          • description += " { " + address.getHost() + ", " + address.getPort() + " }

            ";

          • }
          • description += "]";
          • }
          • } catch (final ClassNotFoundException e) {
          • LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
          • return null;
          • } catch (final NoSuchMethodException e) {
          • LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
          • factoryMethodName, e);
          • return null;
          • } catch (final Exception e) {
          • LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
          • e);
          • return null;
          • }
          • } else if (Strings.isNotEmpty(databaseName)) {
          • final List<MongoCredential> credentials = new ArrayList<>();
          • description = "database=" + databaseName;
          • if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - }
          • try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - }

            catch (final Exception e) {

          • LOGGER.error(
          • "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}].",
          • server, port);
          • return null;
          • }
          • } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - }

            -

          • try { - database.getCollectionNames(); // Check if the database actually requires authentication - }

            catch (final Exception e)

            { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - }

            -

          • final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName);
            -
          • return new MongoDbProvider(database, writeConcern, collectionName, description);
          • }
            + final String collectionName,
            + final String writeConcernConstant,
            + final String writeConcernConstantClassName,
            + final String databaseName,
            + final String server,
            + final String port,
            + final String userName,
            + final String password,
            + final String factoryClassName,
            + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + }

            +
            + @PluginBuilderFactory
            + public static <B extends Builder<B>> B newBuilder()

            { + return new Builder<B>().asBuilder(); + }

            +
            + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B>
            + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> {
            +
            + @PluginBuilderAttribute
            + @ValidHost
            + private String server = "localhost";
            +
            + @PluginBuilderAttribute
            + @ValidPort
            + private String port = "" + DEFAULT_PORT;

              • End diff –

          https://github.com/codescale/logging-log4j2/blob/master/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java#L141

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126504038 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -93,130 +103,249 @@ public String toString() { @param factoryMethodName The name of the public static factory method belonging to the aforementioned factory class. @return a new MongoDB provider. + * @deprecated in 2.8; use {@link #newBuilder()} instead. */ @PluginFactory public static MongoDbProvider createNoSqlProvider( @PluginAttribute("collectionName") final String collectionName, @PluginAttribute("writeConcernConstant") final String writeConcernConstant, @PluginAttribute("writeConcernConstantClass") final String writeConcernConstantClassName, @PluginAttribute("databaseName") final String databaseName, @PluginAttribute(value = "server", defaultString = "localhost") @ValidHost final String server, @PluginAttribute(value = "port", defaultString = "" + DEFAULT_PORT) @ValidPort final String port, @PluginAttribute("userName") final String userName, @PluginAttribute(value = "password", sensitive = true) final String password, @PluginAttribute("factoryClassName") final String factoryClassName, @PluginAttribute("factoryMethodName") final String factoryMethodName) { DB database; String description; if (Strings.isNotEmpty(factoryClassName) && Strings.isNotEmpty(factoryMethodName)) { try { final Class<?> factoryClass = LoaderUtil.loadClass(factoryClassName); final Method method = factoryClass.getMethod(factoryMethodName); final Object object = method.invoke(null); - if (object instanceof DB) { - database = (DB) object; - } else if (object instanceof MongoClient) { if (Strings.isNotEmpty(databaseName)) { - database = ((MongoClient) object).getDB(databaseName); - } else { LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is " + "required.", factoryClassName, factoryMethodName); return null; } } else if (object == null) { LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName); return null; } else { LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}] .", factoryClassName, factoryMethodName, object.getClass().getName()); return null; } - description = "database=" + database.getName(); final List<ServerAddress> addresses = database.getMongo().getAllAddress(); if (addresses.size() == 1) { - description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort(); - } else { description += ", servers=["; for (final ServerAddress address : addresses) { description += " { " + address.getHost() + ", " + address.getPort() + " } "; } description += "]"; } } catch (final ClassNotFoundException e) { LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e); return null; } catch (final NoSuchMethodException e) { LOGGER.error("The factory class [{}] does not have a no-arg method named [{}] .", factoryClassName, factoryMethodName, e); return null; } catch (final Exception e) { LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName, e); return null; } } else if (Strings.isNotEmpty(databaseName)) { final List<MongoCredential> credentials = new ArrayList<>(); description = "database=" + databaseName; if (Strings.isNotEmpty(userName) && Strings.isNotEmpty(password)) { - description += ", username=" + userName + ", passwordHash=" - + NameUtil.md5(password + MongoDbProvider.class.getName()); - credentials.add(MongoCredential.createCredential(userName, databaseName, password.toCharArray())); - } try { - final int portInt = TypeConverters.convert(port, int.class, DEFAULT_PORT); - description += ", server=" + server + ", port=" + portInt; - database = new MongoClient(new ServerAddress(server, portInt), credentials).getDB(databaseName); - } catch (final Exception e) { LOGGER.error( "Failed to obtain a database instance from the MongoClient at server [{}] and " + "port [{}] .", server, port); return null; } } else { - LOGGER.error("No factory method was provided so the database name is required."); - return null; - } - try { - database.getCollectionNames(); // Check if the database actually requires authentication - } catch (final Exception e) { - LOGGER.error( - "The database is not up, or you are not authenticated, try supplying a username and password to the MongoDB provider.", - e); - return null; - } - final WriteConcern writeConcern = toWriteConcern(writeConcernConstant, writeConcernConstantClassName); - return new MongoDbProvider(database, writeConcern, collectionName, description); } + final String collectionName, + final String writeConcernConstant, + final String writeConcernConstantClassName, + final String databaseName, + final String server, + final String port, + final String userName, + final String password, + final String factoryClassName, + final String factoryMethodName) { + LOGGER.info("createNoSqlProvider"); + return newBuilder().setCollectionName(collectionName).setWriteConcernConstant(writeConcernConstantClassName) + .setWriteConcernConstant(writeConcernConstant).setDatabaseName(databaseName).setServer(server) + .setPort(port).setUserName(userName).setPassword(password).setFactoryClassName(factoryClassName) + .setFactoryMethodName(factoryMethodName).build(); + } + + @PluginBuilderFactory + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + } + + public static class Builder<B extends Builder<B>> extends AbstractFilterable.Builder<B> + implements org.apache.logging.log4j.core.util.Builder<MongoDbProvider> { + + @PluginBuilderAttribute + @ValidHost + private String server = "localhost"; + + @PluginBuilderAttribute + @ValidPort + private String port = "" + DEFAULT_PORT; End diff – https://github.com/codescale/logging-log4j2/blob/master/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java#L141
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126504049

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -21,50 +21,60 @@
          import java.util.ArrayList;
          import java.util.List;

          -import com.mongodb.DB;
          -import com.mongodb.MongoClient;
          -import com.mongodb.MongoCredential;
          -import com.mongodb.ServerAddress;
          -import com.mongodb.WriteConcern;
          import org.apache.logging.log4j.Logger;
          +import org.apache.logging.log4j.core.Core;
          import org.apache.logging.log4j.core.config.plugins.Plugin;
          -import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
          +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
          +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
          import org.apache.logging.log4j.core.config.plugins.PluginFactory;
          import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters;
          +import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
          import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidHost;
          import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidPort;
          +import org.apache.logging.log4j.core.filter.AbstractFilterable;
          import org.apache.logging.log4j.core.util.NameUtil;
          import org.apache.logging.log4j.nosql.appender.NoSqlProvider;
          import org.apache.logging.log4j.status.StatusLogger;
          import org.apache.logging.log4j.util.LoaderUtil;
          import org.apache.logging.log4j.util.Strings;

          +import com.mongodb.DB;
          +import com.mongodb.MongoClient;
          +import com.mongodb.MongoCredential;
          +import com.mongodb.ServerAddress;
          +import com.mongodb.WriteConcern;
          +
          /**

          • The MongoDB implementation of {@link NoSqlProvider}

            .
            */
            -@Plugin(name = "MongoDb", category = "Core", printObject = true)
            +@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
            public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> {

          private static final WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED;
          private static final Logger LOGGER = StatusLogger.getLogger();
          private static final int DEFAULT_PORT = 27017;
          + private static final int DEFAULT_COLLECTION_SIZE = 536870912;
          — End diff –

          These changes have been introduced to my pull-request by a rebase from master.
          This change exists there already. see https://github.com/codescale/logging-log4j2/blob/master/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java#L56

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126504049 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -21,50 +21,60 @@ import java.util.ArrayList; import java.util.List; -import com.mongodb.DB; -import com.mongodb.MongoClient; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; -import com.mongodb.WriteConcern; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters; +import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidHost; import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidPort; +import org.apache.logging.log4j.core.filter.AbstractFilterable; import org.apache.logging.log4j.core.util.NameUtil; import org.apache.logging.log4j.nosql.appender.NoSqlProvider; import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.LoaderUtil; import org.apache.logging.log4j.util.Strings; +import com.mongodb.DB; +import com.mongodb.MongoClient; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.WriteConcern; + /** The MongoDB implementation of {@link NoSqlProvider} . */ -@Plugin(name = "MongoDb", category = "Core", printObject = true) +@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true) public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> { private static final WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED; private static final Logger LOGGER = StatusLogger.getLogger(); private static final int DEFAULT_PORT = 27017; + private static final int DEFAULT_COLLECTION_SIZE = 536870912; — End diff – These changes have been introduced to my pull-request by a rebase from master. This change exists there already. see https://github.com/codescale/logging-log4j2/blob/master/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java#L56
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on a diff in the pull request:

          https://github.com/apache/logging-log4j2/pull/62#discussion_r126505047

          — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java —
          @@ -21,50 +21,60 @@
          import java.util.ArrayList;
          import java.util.List;

          -import com.mongodb.DB;
          -import com.mongodb.MongoClient;
          -import com.mongodb.MongoCredential;
          -import com.mongodb.ServerAddress;
          -import com.mongodb.WriteConcern;
          import org.apache.logging.log4j.Logger;
          +import org.apache.logging.log4j.core.Core;
          import org.apache.logging.log4j.core.config.plugins.Plugin;
          -import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
          +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
          +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
          import org.apache.logging.log4j.core.config.plugins.PluginFactory;
          import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters;
          +import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
          import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidHost;
          import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidPort;
          +import org.apache.logging.log4j.core.filter.AbstractFilterable;
          import org.apache.logging.log4j.core.util.NameUtil;
          import org.apache.logging.log4j.nosql.appender.NoSqlProvider;
          import org.apache.logging.log4j.status.StatusLogger;
          import org.apache.logging.log4j.util.LoaderUtil;
          import org.apache.logging.log4j.util.Strings;

          +import com.mongodb.DB;
          +import com.mongodb.MongoClient;
          +import com.mongodb.MongoCredential;
          +import com.mongodb.ServerAddress;
          +import com.mongodb.WriteConcern;
          +
          /**

          • The MongoDB implementation of {@link NoSqlProvider}

            .
            */
            -@Plugin(name = "MongoDb", category = "Core", printObject = true)
            +@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true)
            public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> {

          private static final WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED;
          private static final Logger LOGGER = StatusLogger.getLogger();
          private static final int DEFAULT_PORT = 27017;
          + private static final int DEFAULT_COLLECTION_SIZE = 536870912;
          — End diff –

          Oh, someone else added that in a separate PR, I see.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/62#discussion_r126505047 — Diff: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java — @@ -21,50 +21,60 @@ import java.util.ArrayList; import java.util.List; -import com.mongodb.DB; -import com.mongodb.MongoClient; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; -import com.mongodb.WriteConcern; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters; +import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidHost; import org.apache.logging.log4j.core.config.plugins.validation.constraints.ValidPort; +import org.apache.logging.log4j.core.filter.AbstractFilterable; import org.apache.logging.log4j.core.util.NameUtil; import org.apache.logging.log4j.nosql.appender.NoSqlProvider; import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.LoaderUtil; import org.apache.logging.log4j.util.Strings; +import com.mongodb.DB; +import com.mongodb.MongoClient; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.WriteConcern; + /** The MongoDB implementation of {@link NoSqlProvider} . */ -@Plugin(name = "MongoDb", category = "Core", printObject = true) +@Plugin(name = "MongoDb", category = Core.CATEGORY_NAME, printObject = true) public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> { private static final WriteConcern DEFAULT_WRITE_CONCERN = WriteConcern.ACKNOWLEDGED; private static final Logger LOGGER = StatusLogger.getLogger(); private static final int DEFAULT_PORT = 27017; + private static final int DEFAULT_COLLECTION_SIZE = 536870912; — End diff – Oh, someone else added that in a separate PR, I see.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          Alright, everything looks fine to merge then. @mikaelstaldal you can merge this if you have time.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on the issue: https://github.com/apache/logging-log4j2/pull/62 Alright, everything looks fine to merge then. @mikaelstaldal you can merge this if you have time.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user garydgregory commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          Don't forget to update the docs please.

          Show
          githubbot ASF GitHub Bot added a comment - Github user garydgregory commented on the issue: https://github.com/apache/logging-log4j2/pull/62 Don't forget to update the docs please.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          I must admit I don't know where/how I can help you to keep the docs up to date. If I'm able to help, please point me to the right location thanks.

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on the issue: https://github.com/apache/logging-log4j2/pull/62 I must admit I don't know where/how I can help you to keep the docs up to date. If I'm able to help, please point me to the right location thanks.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          https://github.com/apache/logging-log4j2/blob/master/src/site/xdoc/manual/appenders.xml is the appenders manual page which should be what you're looking for. Just follow the patterns for how to markup the docs.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on the issue: https://github.com/apache/logging-log4j2/pull/62 https://github.com/apache/logging-log4j2/blob/master/src/site/xdoc/manual/appenders.xml is the appenders manual page which should be what you're looking for. Just follow the patterns for how to markup the docs.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mikaelstaldal commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          @jvz I have no experience with our MongoDB appender, and only limited experience with MongoDB in general. Maybe better that you, or someone else with more experience, merge this.

          Show
          githubbot ASF GitHub Bot added a comment - Github user mikaelstaldal commented on the issue: https://github.com/apache/logging-log4j2/pull/62 @jvz I have no experience with our MongoDB appender, and only limited experience with MongoDB in general. Maybe better that you, or someone else with more experience, merge this.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jvz commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          I'm not too experienced with Mongo either because I prefer not losing data, but no worries, I'll take care of merging this now that I've got some time.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jvz commented on the issue: https://github.com/apache/logging-log4j2/pull/62 I'm not too experienced with Mongo either because I prefer not losing data, but no worries, I'll take care of merging this now that I've got some time.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit c2af08d4d899d0ecb0b7f1f5c560b4e87b981243 in logging-log4j2's branch refs/heads/master from Matthias Kappeller
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=c2af08d ]

          LOG4J2-1864: Introduce builder to MongoDbProvider to preserve backwards compatibility

          Show
          jira-bot ASF subversion and git services added a comment - Commit c2af08d4d899d0ecb0b7f1f5c560b4e87b981243 in logging-log4j2's branch refs/heads/master from Matthias Kappeller [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=c2af08d ] LOG4J2-1864 : Introduce builder to MongoDbProvider to preserve backwards compatibility
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit af2dd30e16cece20b4ae475da851c8538bfa8879 in logging-log4j2's branch refs/heads/master from Matt Sicker
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=af2dd30 ]

          LOG4J2-1864 Update manual regarding capped collection support

          Show
          jira-bot ASF subversion and git services added a comment - Commit af2dd30e16cece20b4ae475da851c8538bfa8879 in logging-log4j2's branch refs/heads/master from Matt Sicker [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=af2dd30 ] LOG4J2-1864 Update manual regarding capped collection support
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 662d8387cc553287b54dcf11f999239cba65c4bc in logging-log4j2's branch refs/heads/master from Matt Sicker
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=662d838 ]

          LOG4J2-1864 Add changelog entry

          Show
          jira-bot ASF subversion and git services added a comment - Commit 662d8387cc553287b54dcf11f999239cba65c4bc in logging-log4j2's branch refs/heads/master from Matt Sicker [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=662d838 ] LOG4J2-1864 Add changelog entry
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/logging-log4j2/pull/62

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/logging-log4j2/pull/62
          Hide
          jvz Matt Sicker added a comment -

          Merged to master. I've added some basic doc updates for the two new parameters. Please verify and close.

          Show
          jvz Matt Sicker added a comment - Merged to master. I've added some basic doc updates for the two new parameters. Please verify and close.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit af2dd30e16cece20b4ae475da851c8538bfa8879 in logging-log4j2's branch refs/heads/Lucene5 from Matt Sicker
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=af2dd30 ]

          LOG4J2-1864 Update manual regarding capped collection support

          Show
          jira-bot ASF subversion and git services added a comment - Commit af2dd30e16cece20b4ae475da851c8538bfa8879 in logging-log4j2's branch refs/heads/Lucene5 from Matt Sicker [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=af2dd30 ] LOG4J2-1864 Update manual regarding capped collection support
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 662d8387cc553287b54dcf11f999239cba65c4bc in logging-log4j2's branch refs/heads/Lucene5 from Matt Sicker
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=662d838 ]

          LOG4J2-1864 Add changelog entry

          Show
          jira-bot ASF subversion and git services added a comment - Commit 662d8387cc553287b54dcf11f999239cba65c4bc in logging-log4j2's branch refs/heads/Lucene5 from Matt Sicker [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=662d838 ] LOG4J2-1864 Add changelog entry
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user codescale commented on the issue:

          https://github.com/apache/logging-log4j2/pull/62

          Thanks @jvz for extending the documentation :+1:
          https://github.com/apache/logging-log4j2/commit/af2dd30e16cece20b4ae475da851c8538bfa8879

          Show
          githubbot ASF GitHub Bot added a comment - Github user codescale commented on the issue: https://github.com/apache/logging-log4j2/pull/62 Thanks @jvz for extending the documentation :+1: https://github.com/apache/logging-log4j2/commit/af2dd30e16cece20b4ae475da851c8538bfa8879

            People

            • Assignee:
              jvz Matt Sicker
              Reporter:
              mkappeller Matt
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development