package org.nybatis.core.db.etc;

import ch.qos.logback.classic.Level;
import org.nybatis.core.conf.Const;
import org.nybatis.core.log.NLogger;
import org.nybatis.core.log.NLoggerPrinter;
import org.nybatis.core.worker.WorkerExecute;

/**
 * @author nayasis@gmail.com
 * @since 2017-11-22
 */
public class SqlLogHider {
    public static SqlLogHider $ = new SqlLogHider();
    public void hideDebugLog( WorkerExecute worker ) {

        NLoggerPrinter logger = NLogger.getLogger( Const.db.LOG_SQL );
        Level prevLogLevel = logger.getLevel();

        if( prevLogLevel != null && prevLogLevel.levelInt >= Level.DEBUG.levelInt ) {
            logger.setLevel( Level.INFO );
        }

        try {
            worker.execute();
        } finally {
            logger.setLevel( prevLogLevel );
        }

    }

}

@@ -313,16 +313,17 @@
 Hider %7B%0A
+%0A
     publ
@@ -363,24 +363,25 @@
 LogHider();%0A
+%0A
     public v
@@ -451,15 +451,26 @@
 ter 
-l
+sqlL
 ogger 
+        
 = NL
@@ -503,16 +503,102 @@
 LOG_SQL 
+  );%0A        NLoggerPrinter batchLogger       = NLogger.getLogger( Const.db.LOG_BATCH 
 );%0A     
@@ -606,20 +606,32 @@
   Level 
+         
 prev
+Sql
 LogLevel
@@ -635,11 +635,16 @@
 vel 
-= l
+  = sqlL
 ogge
@@ -657,25 +657,37 @@
 evel();%0A
-%0A
+        Level
         
 if( prev
@@ -682,16 +682,19 @@
     
-if(
+ 
  prev
+batch
 LogL
@@ -702,31 +702,82 @@
 vel 
-!
 = 
-null &&
+batchLogger.getLevel();%0A%0A        setLogLevel( sqlLogger,
  prev
+Sql
 LogLevel
 .lev
@@ -776,43 +776,129 @@
 evel
-.levelInt %3E= Level.DEBUG.levelInt )
+ );%0A        setLogLevel( batchLogger, prevbatchLogLevel );%0A%0A        try %7B%0A            worker.execute();%0A        %7D finally
  %7B%0A 
@@ -900,33 +900,36 @@
 y %7B%0A            
-l
+sqlL
 ogger.setLevel( 
@@ -932,32 +932,81 @@
 el( 
-Level.INFO );%0A        %7D%0A
+prevSqlLogLevel );%0A            batchLogger.setLevel( prevbatchLogLevel );
 %0A   
@@ -1014,61 +1014,189 @@
     
-try %7B
+%7D%0A
 %0A    
+%7D%0A%0A
     
-    worker.execute();%0A        %7D finally
+private void setLogLevel( NLoggerPrinter sqlLogger, Level prevSqlLogLevel ) %7B%0A        if( prevSqlLogLevel != null && prevSqlLogLevel.levelInt %3E= Level.DEBUG.levelInt )
  %7B%0A 
@@ -1206,17 +1206,20 @@
         
-l
+sqlL
 ogger.se
@@ -1230,20 +1230,18 @@
 el( 
-prevLog
 Level
+.INFO
  );%0A
@@ -1246,22 +1246,21 @@
 ;%0A        %7D%0A
-%0A
     %7D%0A%0A%7D%0A

make LogHider working on batch sql logger too.