You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Rostislav Svoboda <bo...@pobox.sk> on 2004/04/27 20:00:26 UTC

Different Layouts for different levels

Hi all

Is it possible to set different Pattern Layouts for different levels and 
thus to save messages to one logfile in a different format? 

If yes does anyone know how to configure the log4j.properties ?

thx  & EOF

Bost

========================================================================
An example:

the logfile in format:

    <Method_M>
        <DEBUG text="variable c is null"></DEBUG>
    </Method_M>
    <Method_N>
        <DEBUG text="variable d is XXX"></DEBUG>
    </Method_N>

is produced by code:

    public void Method_M(String c)
    {
        logger.info("Method_M");                // Method_M: Starting ...
        logger.debug("variable c is: " + c);

        // ... execute Method_M

        logger.info("/Method_M");               // Method_M: Done
        return;
    }    

    public void Method_N(String d)
    {
        logger.info("Method_N");                // Method_N: Starting ...
        logger.debug("variable d is " + d);

        // ... execute Method_N

        logger.info("/Method_N");               // Method_N: Done
        return;
    }

so for INFO level i want to use 
        ConversionPattern=<%m>%n
        
and for DEBUG level i want to use
        ConversionPattern=<%p text="%m"><%p>%n
                

Such pseudo XML format allows me to view the logfile in a XML viewer as a tree 
so i can collapse uninteresting parts of logfile

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org