(招生:13908467300 0731-838616321)牛耳教育十六年专注长沙java培训,是湖南最专业的长沙java培训学校。长沙java培训班招生热线:13908467300 0731-838616321

java培训课程:中用程序修改log4j的输出等级

java培训课程:中用程序修改log4j的输出等级

public static void SetLogLevel(String strAppender, String level){

        if(level == null || strAppender == null)

            return;

        

        Appender appender = Logger.getRootLogger().getAppender(strAppender);

        Level levelSet = Level.toLevel(level);

        if (levelSet != null && appender != null){

            Filter filterIt = appender.getFilter();

            

            while(filterIt != null){

                if(filterIt instanceof LevelRangeFilter){

                    LevelRangeFilter f = (LevelRangeFilter)filterIt;

                    f.setLevelMin(levelSet);

                    break;

                }

                filterIt = filterIt.getNext();

            }

            

            Logger.getRootLogger().setLevel(levelSet);

        }

    }


评论