0

I am using more than debug level. In other words,debug,info,warn,error Printed out in scrren
I would like to make different format by log level in logback.xml.

Format of debug level is %-5level:%msg%n
Format of info level is %-5level.%d{yyyy-MM-dd HH:mm:ss}:%msg%n

Is it possble to make different format by level(debug,info....)?

This is my logback.xml.

<configuration scan="true" scanPeriod="30"> <!--debug level format--> <appender name="STDOUT_DEBUG" class="ch.qos.logback.core.ConsoleAppender"> <target>System.out</target> <encoder> <pattern>%-5level:%msg%n</pattern> </encoder> <!--info level format--> <appender name="STDOUT_INFO" class="ch.qos.logback.core.ConsoleAppender"> <target>System.out</target> <encoder> <pattern>%-5level.%d{yyyy-MM-dd HH:mm:ss}:%msg%n</pattern> </encoder> </appender> <!-- I don't know How to set--> </configuration> 
2
  • I think that you're XML is missing a </appender> Commented Sep 6, 2021 at 8:29
  • Thank you. I forgot to add </appender>. Commented Sep 6, 2021 at 9:34

1 Answer 1

1

You can write your custom layout extending LayoutBase to have the maximum flexibility.

You need to rewrite the code of the doLayout method

public String doLayout(ILoggingEvent event) { switch (event.getLevel()) { ... // Your logic here } } 
Sign up to request clarification or add additional context in comments.

1 Comment

I tried it. It is working well. Thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.