Skip to content

MdcPatternConverter - update output format for log process tool friendly and smaller size #3435

@amosshi

Description

@amosshi

Warning!
It is highly recommended to discuss feature requests in the mailing lists first.

Background

When a log string contains key=value format, in modern log search tool, like Splunk or ELK:

  • The key will become a searchable field
  • The value become the value of the corresponding key, and we can do visualization easily

The Problem

The current output for the MdcPatternConverter is in a similar format to the java.util.Hashtable.toString(), like {key1=value1, key2=value2, key3=value3}

If we have the config bellow:

  • %notEmpty{ %MDC}

log4j2 timestamp=%date{ISO8601} log.level=%level{length=5} log.logger=%logger %notEmpty{ %MDC} %highlight{%message%notEmpty{ throwableMessage="%throwable{short.message}"}}%n

The MDC part sample output will look like

{TID=8C6976E5B54104, company=TEST-COMPANY-1, companyName=Test Company One, hashUserId=8C6976E5B, ipAddress=127.0.0.1, sessionId=45F0AB50, request=11}

Where

  • { and } are not useful for the log search tools (Splunk, ELK, or other tools)
  • , are in fact not needed

The Feature Request

We need an option, named like mdcflatformat=true, to indicate MdcPatternConverter will generate a flat format of:

  • key1=value1 key2=value2 key3=value3

And, then the value contains a space ( ) , the value will be double quoted:

  • key1=value1 key2=value2 key3=value3 key4="value 4"

We will config as

  • %notEmpty{ %MDC}{mdcflatformat}
    • Where mdcflatformat is the new flag we introduced

The sample output above will become

TID=8C6976E5B54104 company=TEST-COMPANY-1 companyName="Test Company One" hashUserId=8C6976E5B ipAddress=127.0.0.1 sessionId=45F0AB50 request=11

Benefits

  • The format will be more log search tool friendly
  • The log generated will be smaller, because we removed the characters of {, , and }
    • Small is important, because in a big system, say we have 1 billion transactions per week, every less character in log will save cost

Action Items

When the community accept this feature request, we can provide PR and test case.

Metadata

Metadata

Assignees

Labels

enhancementAdditions or updates to featureslayoutsAffects one or more Layout plugins

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions