package org.nybatis.core.log.layout;

import org.nybatis.core.util.StringUtil;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.pattern.PatternLayoutEncoderBase;

public class NLoggerPatternLayoutEncoder extends PatternLayoutEncoderBase<ILoggingEvent> {

	@Override
	public void start() {

		boolean hasMessagePatternFlag = StringUtil.nvl(getPattern()).indexOf( "%m" ) >= 0;

		NLoggerPatternLayout patternLayout = hasMessagePatternFlag ? new NLoggerBasicPatternLayout() : new NLoggerPatternLayout();

		patternLayout.setContext( context );
		patternLayout.setPattern( StringUtil.nvl(getPattern(), " ") );
		patternLayout.setOutputPatternAsHeader( outputPatternAsHeader );
		patternLayout.start();

		this.layout = patternLayout;

		super.start();

	}

}

@@ -35,49 +35,8 @@
 t;%0A%0A
-import org.nybatis.core.util.StringUtil;%0A
 impo
@@ -140,16 +140,103 @@
 derBase;
+%0Aimport org.nybatis.core.util.StringUtil;%0Aimport org.nybatis.core.validation.Validator;
 %0A%0Apublic
@@ -360,94 +360,8 @@
  %7B%0A%0A
-%09%09boolean hasMessagePatternFlag = StringUtil.nvl(getPattern()).indexOf( %22%25m%22 ) %3E= 0;%0A%0A
 %09%09NL
@@ -416,12 +416,10 @@
 tern
-Flag
+()
  ? n
@@ -731,10 +731,144 @@
 );%0A%0A%09%7D%0A%0A
+%09private boolean hasMessagePattern() %7B%0A%09%09return Validator.isFound( getPattern(), %22%25(%5B%5E a-zA-Z%25%5D*?)(message%7Cmsg%7Cm)(%5B%5Ea-zA-Z%5D%7C$)%22);%0A%09%7D%0A%0A
 %7D%0A

allow to accept logback message flag pattern