JavaScript日志框架:Log4js

jopen 10年前發布 | 78K 次閱讀 Log4js JavaScript開發

Log4js 是一個用于JavaScript應用的中日志框架。其主要目標是提供一個強大而可靠的日志記錄API,非常類似于Java日志框架Log4j
project-logo.png

當前可用的Appenders有:

  • WindowAppender: open a new window in the browser and insert log messages in real time.
  • WindowsEventAppender: send log messages in the MS Windows event manager.
  • FileAppender: write log messages in a local file on the client.
  • AjaxAppender: allow to send log messages to the server with asynchronous HTTP request. There you can process the logging events like you want on server side (ASP.NET, Java Servlet, JSP, PHP, Ruby, etc.).
    There is also a servlet for receiving these events tolog by Log4j or Java logging in the download section.
  • MetatagAppender: add log messages as meta data.

Many Appender can be used in same time.

用法

Log4js 是一個簡單日的API,需要在你的頁面中包含以下腳本:

 
            <script src="log4js.js" type="text/javascript"></script> 
            <script type="text/javascript"> 
            <!-- // 
            //initialize the logger  with your category 
            var logger = Log4js.getLogger("ajaxTest"); 
            //set the level of logging 
            logger.setLevel(Log4js.Level.ALL); 
            //set the Appender to write the log to 
            logger.addAppender(new AjaxAppender("./log4j.jsp")); 
            // --> </script> 
            

然后你就可以調日志輸出:

               <input type="button" name="trace" value="Trace" 
                    onclick="logger.trace('I was traced!');return false;" /> 

項目主頁:http://www.baiduhome.net/lib/view/home/1399953956567

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!