首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

看一看有什么解决办法

2012-12-24 
看一看有什么解决方法private final static String MATCH_LEVEL ERROR|error|INFO|info|DEBUG|debug|WA

看一看有什么解决方法

    private final static String MATCH_LEVEL = "ERROR|error|INFO|info|DEBUG|debug|WARN|warn|FATAL|fatal";    private static Logger logger = Logger.getLogger("com.huawei.mediax");     public Integer32 getHwLogLevel() throws SnmpException    {        Level Level = logger.getLevel();        if (Level.isGreaterOrEqual(Priority.DEBUG))        {            this.hwLogLevel = new Integer32(1);        }        if (Level.isGreaterOrEqual(Priority.INFO))        {            this.hwLogLevel = new Integer32(2);        }        if (Level.isGreaterOrEqual(Priority.WARN))        {            this.hwLogLevel = new Integer32(3);        }        if (Level.isGreaterOrEqual(Priority.ERROR))        {            this.hwLogLevel = new Integer32(4);        }        if (Level.isGreaterOrEqual(Priority.FATAL))        {            this.hwLogLevel = new Integer32(5);        }        return hwLogLevel;    }         public void modifyLogfile(final Integer32 newValue)    {                //读取配置并组装日志文件log4j.xml的文件路径        String filePath = "";        //mdxdb模块存放log4j.xml文件目录与其他目录不一致        if (ConfigKit.getMoudleType().equals(MDXDBTYPE))        {            filePath = System.getenv("SNMP_HOME") + File.separatorChar + "conf"                    + File.separatorChar + "log4j.xml";        }        else        {            filePath = System.getenv("SNMP_HOME") + File.separatorChar + "conf"                    + File.separatorChar + "server" + File.separatorChar                    + "log4j.xml";                    }                if (logger.isDebugEnabled())        {            logger.debug("The log4j.xml file path is <" + filePath + ">");        }                StringBuilder builder = new StringBuilder();        try        {            //读写文件            File logfile = new File(filePath);            BufferedReader reader = new BufferedReader(new FileReader(logfile));                        if (reader.ready())            {                String tmp = null;                while (null != (tmp = reader.readLine()))                {                    builder.append(tmp).append("\r\n");                    if (-1 != tmp.indexOf("com.huawei.mediax"))                    {                                                String loglevel = reader.readLine();                        //把匹配MATCH_LEVEL中的字符串,修改为传入的字符串                        builder.append(                                loglevel.replaceAll(MATCH_LEVEL,                                        getLogLevelStr(newValue.getValue())))                                .append("\r\n");                    }                                    }                BufferedWriter write = new BufferedWriter(new FileWriter(                        logfile));                write.write(builder.toString());                write.close();                reader.close();                                if (logger.isDebugEnabled())                {                    logger.debug("Changed the content :\r\n" + builder);                }                            }            else            {                logger.error("reader is not ready");            }                    }        catch (FileNotFoundException e)        {            logger.error("Reade log4j file error", e);        }        catch (IOException e)        {            logger.error("Writer log4j file error", e);        }    }    public void setHwLogLevel(final Integer32 newValue) throws SnmpException    {        this.hwLogLevel = newValue;        logger.setLevel(getLogLevel(newValue.getValue()));        if (logger.isDebugEnabled())        {            logger.debug("set Log Level =" + getLogLevel(newValue.getValue()));        }        //修改日志文件        modifyLogfile(newValue);                if (logger.isDebugEnabled())        {            logger.debug("set Log Level success");        }    }}

热点排行