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

Raimar Falke commented on LOG4J2-1694:
--------------------------------------

The use case is that each log message has a common set of attributes. Useful 
are: 
* "environment" with values like prod/live, test, uat, integration, staging3
* "application" to use a single ELK installation for the whole IT department
* "service" to split a single application. Values are "user", "shipping", ...

Application and service are usually fixed for a certain war-file while the 
environment depends on the deployment. 

In the logback case a single config file is created during the 
building/deployment process which ensures that each log message has all these 
attributes. The question is how this could be achieved with log4j.

One solution we discussed internally was to put these attributes in all MDCs. 
But it hard to ensure that each Thread is covered. So I could also image a 
solution which doesn't add this feature to a or multiple Layouts but which 
changes the way the LoggingEvent is created. So that you can specify a fixed 
base set of properties each LoggingEvent will have.


> Allow to easily add fields with fixed values to JSON output
> -----------------------------------------------------------
>
>                 Key: LOG4J2-1694
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1694
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Layouts
>    Affects Versions: 2.7
>            Reporter: Raimar Falke
>              Labels: extra-field, json
>
> The Logback JSON Encoder has a feature which allows to specify JSON fields 
> with fixed values. Link: 
> https://github.com/logstash/logstash-logback-encoder#loggingevent_custom_global
> Example:
> {noformat}
> <encoder class="net.logstash.logback.encoder.LogstashEncoder">
>   
> <customFields>{"appname":"myWebservice","roles":["customerorder","auth"],"buildinfo":{"version":"Version
>  
> 0.1.0-SNAPSHOT","lastcommit":"75473700d5befa953c45f630c6d9105413c16fe1"}}</customFields>
> </encoder>
> {noformat}
> This is a very convenient way to specify fixed attributes like application, 
> service or environment.
> So far I don't see such a possibility in log4j. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to