You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2022/06/02 14:54:00 UTC

[jira] [Commented] (LOG4J2-3529) Log4j Custom Layout always use the Attribute value of the last one created.

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

Ralph Goers commented on LOG4J2-3529:
-------------------------------------

In the code you provided the "application" variable is never defined.

> Log4j Custom Layout always use the Attribute value of the last one created.
> ---------------------------------------------------------------------------
>
>                 Key: LOG4J2-3529
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3529
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Plugins
>            Reporter: XIAOMING ZHAO
>            Priority: Major
>
> Hi Log4j Team,
> I got one problem, I defined custom layout plugin like the following, and defined Appender to set the layout with different application value in log4j2.xml, but I found it always use the application value of the last Appender instead of different value for different appender.  any problem with my code ? how to resolve this kind of issue?
> {code:java}
> @Plugin(name = "UnifiedLoggingFormat", category = Node.CATEGORY,
>         elementType = Layout.ELEMENT_TYPE, printObject = true)
> public class UnifiedLoggingFormat extends AbstractStringLayout
>  
>     protected UnifiedLoggingFormat(String aInApplication, Charset aInCharset)
>     {
>         super(aInCharset);
>         application = aInApplication;
>     }
>     @PluginFactory
>     public static UnifiedLoggingFormat createLayout(
>             @PluginAttribute(value="Application",
>                     defaultString = DEFAULT_APPLICATION)
>                     String aInApplication,
>             @PluginAttribute(value = "charset", defaultString = "UTF-8")
>                     Charset aInCharset)
>     {
>         return new UnifiedLoggingFormat(aInApplication, aInCharset);
>      }
> {code}
> log4j2.xml like the following:
>  
>  
> {code:java}
>        <RollingFile name="ServerFileAppender"
>                      fileName="/opt/tpa/logs/Server.log"
>                      filePattern="/opt/tpa/logs/Server/Server.%i.log.gz">
>             <UnifiedLoggingFormat/>
>             <AddMDCFilter/>
>             <Policies>
>                 <SizeBasedTriggeringPolicy size="30 MB"/>
>             </Policies>
>             <DefaultRolloverStrategy fileIndex="min" min="1" max="10">
>       
>             </DefaultRolloverStrategy>
>         </RollingFile>
>         <Socket name="Socket_ServerFileAppender"
>                 host="localhost"
>                 port="8514"
>                 reconnectionDelayMillis="10000">
>             <UnifiedLoggingFormat Application="SERVER"/>
>         </Socket>
>         <Socket name="Socket_RSArmingFileAppender"
>                 host="localhost"
>                 port="8514"
>                 reconnectionDelayMillis="10000">
>             <UnifiedLoggingFormat Application="ARMING"/>
>         </Socket>
>  
> {code}
>    
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)