var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-20738293-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script')"/>
<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jutleo
    歡迎走進(jìn)有風(fēng)的地方~~
    posts - 63,  comments - 279,  trackbacks - 0
    關(guān)于Log4j的使用看代碼吧!注釋寫的很詳細(xì),苦于沒有運(yùn)行日志信息的代碼,寫那些helloworld顯得不合適,寫出了五種遍歷List的方法,沒有專門的測試工具測試他們運(yùn)行的效率,哪位要是能測試一下,煩請告訴具體情況!
    package org.bulktree.log4j;

    import java.util.ArrayList;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.List;

    import org.apache.log4j.BasicConfigurator;
    import org.apache.log4j.Logger;

    public class Log4jTest {

        
    // 獲取日志記錄器
        static Logger logger = Logger.getLogger(Log4jTest.class);

        
    // static Logger logger = Logger.getLogger(Log4jTest.class.getName());

        Log4jTest() 
    {
            
    // 配置日志環(huán)境

            
    // 使用缺省Log4j環(huán)境
            BasicConfigurator.configure();
            
    // 讀取使用Java屬性文件編寫的配置文件
            
    // PropertyConfigurator.configure("log4j.properties");
            
    // 讀取XML形式的配置文件
            
    // DOMConfigurator.configure(String filename);
        }


        
    public static void main(String[] args) {

            logger.debug(
    "Log4jTest-->>debug");
            logger.info(
    "Log4jTest-->>info");
            logger.warn(
    "Log4jTest-->>warn");
            logger.error(
    "Log4jTest-->>error");

            System.out.println(
    "************test****************");

            List
    <String> list = new ArrayList<String>();

            list.add(
    "BULKTREE");
            logger.debug(
    "debug-->>List Success! " + "list information: " + list);
            logger.info(
    "info-->>List Success! " + "list information: " + list);
            logger.warn(
    "warn-->>List Success! " + "list information: " + list);
            logger.error(
    "error-->>List Success! " + "list information: " + list);

            list.add(
    "LAOSHULIN");
            logger.debug(
    "debug-->>List Success! " + "list information: " + list);
            logger.info(
    "info-->>List Success! " + "list information: " + list);
            logger.warn(
    "warn-->>List Success! " + "list information: " + list);
            logger.error(
    "error-->>List Success! " + "list information: " + list);

            list.add(
    "OAKERTREE");
            logger.debug(
    "debug-->>List Success! " + "list information: " + list);
            logger.info(
    "info-->>List Success! " + "list information: " + list);
            logger.warn(
    "warn-->>List Success! " + "list information: " + list);
            logger.error(
    "error-->>List Success! " + "list information: " + list);

            list.add(
    "BULKTREE.LAOSHULIN.OAKERTREE");
            logger.debug(
    "debug-->>List Success! " + "list information: " + list);
            logger.info(
    "info-->>List Success! " + "list information: " + list);
            logger.warn(
    "warn-->>List Success! " + "list information: " + list);
            logger.error(
    "error-->>List Success! " + "list information: " + list);

            Log4jTest lt 
    = new Log4jTest();
            lt.firstReadList(list);
            lt.secendReadList(list);
            lt.threeReadList(list);
            lt.fourReadList(list);
            lt.fiveReadList(list);
        }


        
    public void firstReadList(List<String> list) {
            
    for (Iterator<String> iter = list.iterator(); iter.hasNext();) {

                String str 
    = iter.next();
                logger.debug(
    "debug-->>Iterator have next element:" + str);
                logger.info(
    "info-->>Iterator have next element:" + str);
                logger.warn(
    "warn-->>Iterator have next element:" + str);
                logger.error(
    "error-->>Iterator have next element:" + str);

                System.out.println(
    "*********" + str);
            }

        }


        
    public void secendReadList(List<String> list) {
            
    for (int i = 0; i < list.size(); i++{

                String str 
    = list.get(i);
                logger.debug(
    "debug-->>Iterator have next element:" + str);
                logger.info(
    "info-->>Iterator have next element:" + str);
                logger.warn(
    "warn-->>Iterator have next element:" + str);
                logger.error(
    "error-->>Iterator have next element:" + str);

                System.out.println(
    "========" + str);
            }

        }


        
    public void threeReadList(List<String> list) {
            
    for (String str : list) {
                logger.debug(
    "debug-->>Iterator have next element:" + str);
                logger.info(
    "info-->>Iterator have next element:" + str);
                logger.warn(
    "warn-->>Iterator have next element:" + str);
                logger.error(
    "error-->>Iterator have next element:" + str);

                System.out.println(
    "&&&&&&&&" + str);
            }

        }


        
    public void fourReadList(List<String> list) {
            
    for (int i = 0, a = list.size(); i < a; i++{

                String str 
    = list.get(i);
                logger.debug(
    "debug-->>Iterator have next element:" + str);
                logger.info(
    "info-->>Iterator have next element:" + str);
                logger.warn(
    "warn-->>Iterator have next element:" + str);
                logger.error(
    "error-->>Iterator have next element:" + str);

                System.out.println(
    "########" + str);
            }

        }


        
    public void fiveReadList(List<String> list) {
            Iterator
    <String> iter = list.iterator();
            
    while (iter.hasNext()) {

                String str 
    = iter.next();
                logger.debug(
    "debug-->>Iterator have next element:" + str);
                logger.info(
    "info-->>Iterator have next element:" + str);
                logger.warn(
    "warn-->>Iterator have next element:" + str);
                logger.error(
    "error-->>Iterator have next element:" + str);

                System.out.println(
    "$$$$$$$$" + str);
            }

        }

    }



    # An example log4j configuration file that outputs to System.out.  The
    # output information consists of relative time, log level, thread
    # name, logger name, nested diagnostic context and the message in that
    # order.

    # For the general syntax of property based configuration files see the
    # documenation of org.apache.log4j.PropertyConfigurator.

    #配置根Logger,語法為:log4j.rootLogger=[level],appenderName,appenderName,.
    #level是日志記錄器的優(yōu)先級(jí),Log4j建議只使用四個(gè)級(jí)別,從高到低分別是ERROR,
    #WARN,INFO,DEBUG,通過在這里定義的級(jí)別,您可以控制到應(yīng)用程序中相應(yīng)級(jí)別的日志信息的開關(guān)。
    #比如在這里定義了INFO級(jí)別,則應(yīng)用程序中所有DEBUG級(jí)別的日志信息將不被打印出來
    #appenderName指的是制定日志信息輸出到哪個(gè)地方
    #A1標(biāo)識(shí)輸出控制臺(tái),A2標(biāo)識(shí)輸出到日志文件
    log4j.rootLogger=DEBUG, A1,A2
    #Log4j提供的appender有以下幾種: 
    #org.apache.log4j.ConsoleAppender(控制臺(tái)) 
    #org.apache.log4j.FileAppender(文件)
    #org.apache.log4j.DailyRollingFileAppender(每天產(chǎn)生一個(gè)日志文件)
    #org.apache.log4j.RollingFileAppender(文件大小到達(dá)指定尺寸的時(shí)候產(chǎn)生一個(gè)新的文件) 
    #org.apache.log4j.WriterAppender(將日志信息以流格式發(fā)送到任意指定的地方
    # A1 is set to be a ConsoleAppender which outputs to System.out. 
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    log4j.appender.A2=org.apache.log4j.RollingFileAppender
    log4j.appender.A2.File=Log4jTest.log
    #如果超過20KB則自動(dòng)新建一個(gè)文件,文件名后面自動(dòng)加序號(hào)
    log4j.appender.A2.MaxFileSize=20KB

    # A1 uses PatternLayout.
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout

    # The conversion pattern uses format specifiers. You might want to
    # change the pattern an watch the output format change.
    log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n

    # In this example, we are not really interested in INNER loop or SWAP
    # messages. See the effects of uncommenting and changing the levels of
    # the following loggers.
    # log4j.logger.org.apache.log4j.examples.SortAlgo.INNER=WARN
    # log4j.logger.org.apache.log4j.examples.SortAlgo.SWAP=WARN

    # Keep one backup file
    log4j.appender.A2.MaxBackupIndex=1
    log4j.appender.A2.layout=org.apache.log4j.PatternLayout
    log4j.appender.A2.layout.ConversionPattern=%p %t %c - %m%n
    # Print only messages of level WARN or above in the package com.foo.
    log4j.logger.org.bulktree=DEBUG
     
    posted on 2008-08-13 13:59 凌晨風(fēng) 閱讀(2104) 評論(6)  編輯  收藏 所屬分類: Java學(xué)習(xí)筆記

    FeedBack:
    # re: Log4j的使用
    2008-08-14 11:37 | 異次元
    不錯(cuò),收藏了  回復(fù)  更多評論
      
    # re: Log4j的使用
    2008-08-14 17:39 | KingBack
    不錯(cuò), 收藏

    想請教一下晨風(fēng): 我看過你那遍關(guān)于 struts2 中 select tag的用法之后, 還不是很明白, 自己試做也沒能成功, 能否請你把有關(guān) select tag的用法詳細(xì)解釋一下呢? Thanks!  回復(fù)  更多評論
      
    # re: Log4j的使用
    2008-08-14 20:36 | 凌晨風(fēng)
    http://struts.apache.org/2.1.2/docs/select.html這個(gè)是List tag的詳細(xì)介紹。List tag只有l(wèi)ist屬性是必須的,
    request范圍內(nèi)有個(gè)List集合(student)里裝著所有學(xué)生的姓名,你應(yīng)該這樣遍歷:<s:select list="student" name="selectTest" />
    這樣僅限于展示出數(shù)據(jù)。
    你可以對照著HTML:
    <select name="selectTest">
    <option value="">請選擇</option>
    <option value="0">bulktree</option>
    <option value="1">oakertree</option>
    <option value="2">laoshulin</option>
    </select>
      回復(fù)  更多評論
      
    # re: Log4j的使用
    2008-08-14 20:47 | 凌晨風(fēng)
    當(dāng)你把數(shù)據(jù)展示出來后要是還需要下一步的傳輸,在下一個(gè)頁面獲得select中選中的值,Example:request.getParameter("selectTest");對于HTML值為0對應(yīng)顯示是"bulktree",而Struts2 List Tags,則是listKey對應(yīng)ListValue,headerKey對應(yīng)headerValue  回復(fù)  更多評論
      
    # re: Log4j的使用
    2008-08-15 09:33 | KingBack
    Great! I had resolved the problem. Thanks a lot :)

    Cause is not initialize List, after i had initialized it in execute method, i run it successfully.

    Thanks again.  回復(fù)  更多評論
      
    # re: Log4j的使用[未登錄]
    2009-03-11 15:59 | Raul
    打個(gè)時(shí)間戳看看執(zhí)行效率唄  回復(fù)  更多評論
      

    <2008年8月>
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    常用鏈接

    留言簿(11)

    我參與的團(tuán)隊(duì)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    收藏夾

    圍脖

    最新隨筆

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 午夜视频免费观看| 99免费在线视频| 亚洲成熟丰满熟妇高潮XXXXX| 亚洲一级毛片在线播放| 亚洲精品综合久久中文字幕| 91嫩草私人成人亚洲影院| 亚洲AV乱码一区二区三区林ゆな| 亚洲国产日韩在线视频| 亚洲AV无码欧洲AV无码网站| 亚洲AV无码一区二区三区系列 | 中文字幕在线免费观看视频| 日韩精品无码永久免费网站| fc2免费人成在线视频| 男人天堂免费视频| 国产午夜免费高清久久影院| 国产成人精品无码免费看| 91精品国产免费入口| 2019中文字幕免费电影在线播放| 最近2019中文字幕免费直播| 青青青免费国产在线视频小草| 成年人性生活免费视频| 四虎永久在线免费观看| 亚洲精品综合久久| 亚洲av中文无码乱人伦在线r▽ | 亚洲三级电影网站| 亚洲乱人伦精品图片| 亚洲欧洲av综合色无码| 偷自拍亚洲视频在线观看99| jizz免费一区二区三区| 24小时免费看片| 日本媚薬痉挛在线观看免费| 国产成人精品曰本亚洲79ren| 亚洲精品tv久久久久久久久| 亚洲成人黄色在线| 亚洲av日韩综合一区二区三区| 一级毛片免费播放视频| 久久久精品免费视频| 久九九精品免费视频| 免费A级毛片在线播放不收费| 亚洲人精品午夜射精日韩| 久久久无码精品亚洲日韩京东传媒|