Log4j 2
  1. Log4j 2
  2. LOG4J2-404

"@EnterpriseNumber" is missing in the ID of structured data when RFC5424Layout is used

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta9
    • Fix Version/s: None
    • Component/s: Layouts
    • Labels:
      None

      Description

      Prior to beta9, when RFC5424 layout was used, the ID hasd the format "id@ein". With beta9, "@ein" is missing. Example

      Prior to beta9:

      <128>1 2013-09-16T02:07:24.027-07:00 myhost.com MyTestApp - Audit [stopPayment@12293 accountNumber="REPLACE" amount="***" checkNumber="***" comment="Changed mind" endSequence="4322" errorMessage="None" guId="669317b1-1eaf-11e3-80ec-005056b5071b" issueDate="20110504"][RequestContext@12293 ReqCtx_sessionId="66927b70***" ReqCtx_timezone="America/Los_Angeles" ReqCtx_tzOffset="-0800" ReqCtx_userProduct="IB" ReqCtx_userProductVersion="4.18.1"]

      With beta9:

      <128>1 2013-09-16T02:07:24.027-07:00 myhost.com MyTestApp - Audit [stopPayment accountNumber="REPLACE" amount="***" checkNumber="***" comment="Changed mind" endSequence="4322" errorMessage="None" guId="669317b1-1eaf-11e3-80ec-005056b5071b" issueDate="20110504"][RequestContext@12293 ReqCtx_sessionId="66927b70***" ReqCtx_timezone="America/Los_Angeles" ReqCtx_tzOffset="-0800" ReqCtx_userProduct="IB" ReqCtx_userProductVersion="4.18.1"]

      "@12293" is missing after the ID (stopPayment).

        Activity

        Kamal Bahadur created issue -
        Hide
        Kamal Bahadur added a comment -

        I see that the method private String getId(final StructuredDataId id) is not being called.

        Show
        Kamal Bahadur added a comment - I see that the method private String getId(final StructuredDataId id) is not being called.
        Kamal Bahadur made changes -
        Field Original Value New Value
        Comment [ I updated the method private void appendStructuredElements(final StringBuilder buffer, final LogEvent event) and it seem to fix the problem:

        private void appendStructuredElements(final StringBuilder buffer, final LogEvent event) {
                final Message message = event.getMessage();
                final boolean isStructured = message instanceof StructuredDataMessage;

                if (!isStructured && (fieldFormatters!= null && fieldFormatters.size() == 0) && !includeMDC) {
                    buffer.append("-");
                    return;
                }

                final Map<String, StructuredDataElement> sdElements = new HashMap<String, StructuredDataElement>();
                final Map<String, String> contextMap = event.getContextMap();

                if (mdcRequired != null) {
                    checkRequired(contextMap);
                }

                if (fieldFormatters != null) {
                    for (final Map.Entry<String, FieldFormatter> sdElement: fieldFormatters.entrySet()) {
                        final String sdId = sdElement.getKey();
                        final StructuredDataElement elem = sdElement.getValue().format(event);
                        sdElements.put(sdId, elem);
                    }
                }

                if (includeMDC && contextMap.size() > 0) {
                    if (sdElements.containsKey(mdcSDID.toString())) {
                        final StructuredDataElement union = sdElements.get(mdcSDID.toString());
                        union.union(contextMap);
                        sdElements.put(mdcSDID.toString(), union);
                    } else {
                        final StructuredDataElement formattedContextMap = new StructuredDataElement(contextMap, false);
                        sdElements.put(mdcSDID.toString(), formattedContextMap);
                    }
                }

                if (isStructured) {
                    final StructuredDataMessage data = (StructuredDataMessage) message;
                    final Map<String, String> map = data.getData();
                    final StructuredDataId id = data.getId();
                    final String sdId = getId(id);

                    if (sdElements.containsKey(sdId)) {
                        final StructuredDataElement union = sdElements.get(id.toString());
                        union.union(map);
                        sdElements.put(sdId, union);
                    } else {
                        final StructuredDataElement formattedData = new StructuredDataElement(map, false);
                        sdElements.put(sdId, formattedData);
                    }
                }

                if (sdElements.size() == 0) {
                    buffer.append("-");
                    return;
                }

                for (final Map.Entry<String, StructuredDataElement> entry: sdElements.entrySet()) {
                    formatStructuredElement(entry.getKey(), mdcPrefix, entry.getValue(), buffer, checker);
                }
            } ]
        Hide
        Kamal Bahadur added a comment -

        Attached is the patch.

        Show
        Kamal Bahadur added a comment - Attached is the patch.
        Kamal Bahadur made changes -
        Attachment RFC5424Layout.patch.txt [ 12603939 ]
        Hide
        Kamal Bahadur added a comment -

        Is there anything I can do to get this patch committed? This is blocking our production release.

        Show
        Kamal Bahadur added a comment - Is there anything I can do to get this patch committed? This is blocking our production release.
        Kamal Bahadur made changes -
        Priority Critical [ 2 ] Blocker [ 1 ]
        Hide
        Gary Gregory added a comment -

        Ralph, I think you did some work recently in these classes WRT to SD elements. Is this bug a side effect? Does the patch look OK to you? It sounds like a regression due to the lack of a unit test.

        Show
        Gary Gregory added a comment - Ralph, I think you did some work recently in these classes WRT to SD elements. Is this bug a side effect? Does the patch look OK to you? It sounds like a regression due to the lack of a unit test.
        Hide
        Ralph Goers added a comment -

        This is a side effect of LOG4J2-355 which you applied. Unfortunately, I have been very busy and didn't sufficiently review that patch. I did notice that the unit test was changed, which raised some concern but at first glance it looked like it might have been correcting a mistake. Now I am not so sure.

        Show
        Ralph Goers added a comment - This is a side effect of LOG4J2-355 which you applied. Unfortunately, I have been very busy and didn't sufficiently review that patch. I did notice that the unit test was changed, which raised some concern but at first glance it looked like it might have been correcting a mistake. Now I am not so sure.
        Hide
        Kamal Bahadur added a comment -

        Is this fix available in the snapshot?

        Show
        Kamal Bahadur added a comment - Is this fix available in the snapshot?
        Hide
        Gary Gregory added a comment -

        @Kamal, could you please provide another patch for a unit tests? See org.apache.logging.log4j.core.layout.RFC5424LayoutTest. (I am sick today).

        Show
        Gary Gregory added a comment - @Kamal, could you please provide another patch for a unit tests? See org.apache.logging.log4j.core.layout.RFC5424LayoutTest. (I am sick today).
        Hide
        Kamal Bahadur added a comment -

        This attached patch contains unit test that catches this bug.

        Show
        Kamal Bahadur added a comment - This attached patch contains unit test that catches this bug.
        Kamal Bahadur made changes -
        Hide
        Ralph Goers added a comment -

        Both patches were applied in revision 1526807. Please verify and close.

        Show
        Ralph Goers added a comment - Both patches were applied in revision 1526807. Please verify and close.
        Ralph Goers made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Kamal Bahadur added a comment -

        This is working fine now.

        Show
        Kamal Bahadur added a comment - This is working fine now.
        Kamal Bahadur made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Kamal Bahadur
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development