SHARE
TWEET

Untitled

a guest Aug 25th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ch.qos.logback.classic.Level;
  2. import ch.qos.logback.classic.LoggerContext;
  3. import org.slf4j.LoggerFactory;
  4.  
  5. import java.util.Arrays;
  6. import java.util.List;
  7.  
  8. public class LogUtils
  9. {
  10.     private final static List VALID_LEVELS = Arrays.asList( "TRACE", "DEBUG", "INFO", "WARN", "ERROR" );
  11.  
  12.     public static void setLogLevel( String packageName, String logLevel )
  13.     {
  14.         LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
  15.  
  16.         ch.qos.logback.classic.Logger logger = loggerContext.getLogger( packageName );
  17.         System.out.println( packageName + " current logger level: " + logger.getLevel() );
  18.         System.out.println( " You entered: " + logLevel );
  19.  
  20.         if ( VALID_LEVELS.contains( logLevel ) )
  21.         {
  22.             logger.setLevel( Level.toLevel( logLevel ) );
  23.         }
  24.     }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top