-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MdcPatternConverter - update output format for log process tool friendly and smaller size #3435
Comments
Sorry, but I do not believe this is a valid concern. The
If you want the output of Log4j Core to be machine-readable, use a structured layout such as JSON Template Layout or RFC 5424 Layout and parse the output using the appropriate parser. Note: the behavior you are proposing might be useful to emulate Logback's |
@amosshi, it sounds counter intuitive to me to serialize the entire log event into one big string instead of using individual fields wherever necessary. As a matter of fact, both ELK (via its Elastic Common Schema) and Splunk (in its logging best-practices page) recommend using structured logging, which is best delivered by JSON Template Layout. Would you mind helping us to understand your motivation from deviating these standards? Could using a structured layout instead of Pattern Layout be an option for you? |
Hi @vy, The reason do not want to adopt JSON Template Layout in production yet is
Either work with one of the default JSON layouts or a customized JSON layout , JSON log size will be 20% - 100% bigger than the Pattern Layout depending on which additional fields we added to log and how application code logs. So bigger log size may translate to millions of additional dollars of Splunk license cost, depending on x/y/z reasons. |
Looking at your example you implement some sort of tracing:
Since most of those properties ( |
HI @ppkarwasz, The term "structured layout" here, means to "key=value" format. When the log message is in key=value format, Both Splunk and ELK can recognize the keys automatically as a searchable filed. So we can do filter, reporting, dashboard based on the key. Sample: we may have a Pattern Layout log looks like bellow, and the row bellow can be considered as "Structured" somehow, because Splunk/ELK can extract the keys automatically
Where
It will be more perfect if MdcPatternConverter can generate a format like bellow, where the
Benefits
|
We use the term "structured layout" for formats that can be deterministically deserialized. The simple
If you are looking for a structured layout that resembles the Pattern layout, try the RFC5424 layout. The
|
@ppkarwasz Thanks a lot for the feedback
|
@amosshi, note that you can implement your custom MDC converter for Pattern Layout too. |
|
Let us know, when you make your first release, so we can advertise the plugin in our documentation. |
Closing this discussion as resolved since Pattern Layout is not intended for structured logging and a solution is provided for the user. |
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:key
will become a searchable fieldvalue
become the value of the corresponding key, and we can do visualization easilyThe 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}
The MDC part sample output will look like
Where
{
and}
are not useful for the log search tools (Splunk, ELK, or other tools),
are in fact not neededThe 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
) , the value will be double quoted:
space
(key1=value1 key2=value2 key3=value3 key4="value 4"
We will config as
%notEmpty{ %MDC}{mdcflatformat}
mdcflatformat
is the new flag we introducedThe sample output above will become
Benefits
{
,,
and}
Action Items
When the community accept this feature request, we can provide PR and test case.
The text was updated successfully, but these errors were encountered: