Log4j 2
  1. Log4j 2
  2. LOG4J2-331

“ERROR Failed to write log event to MongoDB due to invalid result [0]” when using NoSQLAppender

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta8
    • Fix Version/s: 2.0-beta9
    • Component/s: Appenders
    • Labels:
      None
    • Environment:

      JDK 1.7, Mongo Driver 2.11.2

      Description

      I get following message

      ERROR Failed to write log event to MongoDB due to invalid result [0]

      when using NoSQLAppender with log4j2 v2.0-beta8 but log event gets written to MongoDB.

      Here is my config

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration status="WARN">
      <appenders>
      <NoSql name="databaseAppender" suppressExceptions="true">
      <MongoDb collectionName="applicationLog" factoryClassName="com.borsch.DBManager" factoryMethodName="getNewMongoClient" writeConcernConstant="NONE" username="root" password="qwe"/>
      </NoSql>
      </appenders>
      <loggers>
      <root level="error">
      <appender-ref ref="databaseAppender"/>
      </root>
      </loggers>
      </configuration>

      What's even more strange I can't find the code that generates it. I didn't find such string in sources of log4j2.

        Activity

        Hide
        Nick Williams added a comment -

        The error messages have changed slightly since beta8. Message is in org.apache.logging.log4j.core.appender.db.nosql.mongo.MongoDBConnection.

        I'm not sure why the driver reports no records are written. If you see records written to your MongoDB database, then I'll remove the check.

        Show
        Nick Williams added a comment - The error messages have changed slightly since beta8. Message is in org.apache.logging.log4j.core.appender.db.nosql.mongo.MongoDBConnection. I'm not sure why the driver reports no records are written. If you see records written to your MongoDB database, then I'll remove the check.
        Hide
        Ruslan added a comment -

        Hey Nick,

        Thank you for such prompt response! You can remove the check because getN() returns number of affected documents only for update operations. Inserts always return zero.

        Show
        Ruslan added a comment - Hey Nick, Thank you for such prompt response! You can remove the check because getN() returns number of affected documents only for update operations. Inserts always return zero.
        Hide
        Ruslan added a comment -

        And for errors it's better to check WriteResult.getError(). If there was an error value will be non null.

        Show
        Ruslan added a comment - And for errors it's better to check WriteResult.getError(). If there was an error value will be non null.
        Hide
        Nick Williams added a comment -

        Yea, the current version checks BOTH WriteResult#getError() AND WriteResult#getN(). I understand now why getN() returns zero. I'll remove that check.

        Show
        Nick Williams added a comment - Yea, the current version checks BOTH WriteResult#getError() AND WriteResult#getN() . I understand now why getN() returns zero. I'll remove that check.
        Hide
        Nick Williams added a comment -

        Fixed in trunk. Please verify (either by compiling trunk or waiting for beta9) and close.

        Show
        Nick Williams added a comment - Fixed in trunk. Please verify (either by compiling trunk or waiting for beta9) and close.

          People

          • Assignee:
            Nick Williams
            Reporter:
            Ruslan
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development