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

CsvParameterLayout and CsvLogEventLayout insert NUL character if data starts with {, (, [ or "

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.6.2
    • 2.7
    • Layouts
    • None

    Description

      I am using CsvParameterLayout to generate a CSV file out of log4j2. One of the column is a JSON string. Following is the logger method I am using:

      logger.info("log:{}",json);
      

      Following is the JSON string:

      {"id":10,"name":"sumit"}

      And following is the string which is getting printed in CSV output file:

      NUL

      {"id":10,"name":"sumit"}

      NUL

      The NUL character is the \x00 character. When I open the file in notepad++, then only this character appears. In notepad it shows as space. This poses a problem in CSV processing module.

      If there is some alphabet before {, then the output in CSV is fine. It seems as if log4j is escaping '{' with a NUL character. It is happening if the string starts with

      {, (, [, ' or ". Following are the dependencies: {code:xml}

      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.6.2</version>
      </dependency>
      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.6.2</version>
      </dependency>
      <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-csv</artifactId>
      <version>1.4</version>
      </dependency>

      
      

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            sumit23 Sumit Singhal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment