You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2017/12/04 05:21:00 UTC

[jira] [Commented] (LOG4J2-2140) MutableLogEvent instances get reused before flushing when using a NoSql Appender with a bufferSize

    [ https://issues.apache.org/jira/browse/LOG4J2-2140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16276299#comment-16276299 ] 

Remko Popma commented on LOG4J2-2140:
-------------------------------------

This reminds me of LOG4J2-2060 which was fixed in Log4j 2.10.0.
Is this still an issue if you upgrade to 2.10?

> MutableLogEvent instances get reused before flushing when using a NoSql Appender with a bufferSize
> --------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-2140
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2140
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.9.1
>         Environment: Windows 10 with MongoDB Server 3.4
>            Reporter: Yasas Gunarathne
>
> When using *NoSql* Appender with a *bufferSize* configured *MutableLogEvent* instances get overwritten while they are still in the *buffer* of *AbstractDatabaseManager*. Here are the steps to recreate the issue.
> *log4j2.xml* file I used is as below.
> {code:xml}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration xmlns="http://logging.apache.org/log4j/2.0/config">
>     <Loggers>
>         <Logger name="test.TestOne" level="DEBUG">
>             <AppenderRef ref="NoSql"/>
>         </Logger>
>     </Loggers>
>     <Appenders>
>         <NoSql name="NoSql" bufferSize="100">
>             <MongoDb databaseName="test" collectionName="sampleLogs" server="localhost" />
>         </NoSql>
>     </Appenders>
> </Configuration>
> {code}
> This is the sample program.
> {code:java}
> package test;
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
> public class TestOne {
>     private static final Logger logger = LogManager.getLogger(TestOne.class);
>     public static void main(String[] args) {
>         for (int i = 0; i < 100; i++) {
>             logger.debug("Test: " + i);
>         }
>     }
> }
> {code}
> And here are some of the results I got when querying the MongoDB collection after running the above sample program.
> {noformat}
> {
>   "_id": ObjectId(
>   "5a24d2d332fc4edab1eceb21"
>   ),
>   "level": "DEBUG",
>   "loggerName": "test.TestOne",
>   "message": "Test: 99",
>   "source": {
>     "className": "test.TestOne",
>     "methodName": "main",
>     "fileName": "TestOne.java",
>     "lineNumber": 12
>   },
>   "marker": null,
>   "threadId": NumberLong(1),
>   "threadName": "main",
>   "threadPriority": 5,
>   "millis": NumberLong(
>   "1512362702533"
>   ),
>   "date": ISODate(
>   "2017-12-04T04:45:02.533Z"
>   ),
>   "thrown": null,
>   "contextMap": {},
>   "contextStack": []
> }
> {
>   "_id": ObjectId(
>   "5a24d2d532fc4edab1eceb22"
>   ),
>   "level": "DEBUG",
>   "loggerName": "test.TestOne",
>   "message": "Test: 99",
>   "source": {
>     "className": "test.TestOne",
>     "methodName": "main",
>     "fileName": "TestOne.java",
>     "lineNumber": 12
>   },
>   "marker": null,
>   "threadId": NumberLong(1),
>   "threadName": "main",
>   "threadPriority": 5,
>   "millis": NumberLong(
>   "1512362702533"
>   ),
>   "date": ISODate(
>   "2017-12-04T04:45:02.533Z"
>   ),
>   "thrown": null,
>   "contextMap": {},
>   "contextStack": []
> }
> {
>   "_id": ObjectId(
>   "5a24d2dc32fc4edab1eceb23"
>   ),
>   "level": "DEBUG",
>   "loggerName": "test.TestOne",
>   "message": "Test: 99",
>   "source": {
>     "className": "test.TestOne",
>     "methodName": "main",
>     "fileName": "TestOne.java",
>     "lineNumber": 12
>   },
>   "marker": null,
>   "threadId": NumberLong(1),
>   "threadName": "main",
>   "threadPriority": 5,
>   "millis": NumberLong(
>   "1512362702533"
>   ),
>   "date": ISODate(
>   "2017-12-04T04:45:02.533Z"
>   ),
>   "thrown": null,
>   "contextMap": {},
>   "contextStack": []
> }
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)