Log4j로 검색한 결과 :: 시소커뮤니티[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

회원가입 I 비밀번호 찾기


SSISO Community검색
SSISO Community메뉴
[카페목록보기]
[블로그등록하기]  
[블로그리스트]  
SSISO Community카페
블로그 카테고리
정치 경제
문화 칼럼
비디오게임 스포츠
핫이슈 TV
포토 온라인게임
PC게임 에뮬게임
라이프 사람들
유머 만화애니
방송 1
1 1
1 1
1 1
1 1
1

Log4j로 검색한 결과
등록일:2008-03-14 09:20:44
작성자:
제목:log4j 를 Tomcat 에서 사용하기...


작성자  :  양승진  
LastUpdate  :  2004  /  06  /  30
메일  :  sj99yang@naver.com

  

0.

      OS      :  Windows  2000

      WAS  :  Tomcat  4.1.30

      파일경로  :  WebApp  =  C:\Apache_Group\Tomcat4130\webapps\ROOT

  

  

  

1.  Log4j  초기화에  필요한  서블릿  생성

      파일경로  :  %WebApp%/WEB-INF/classes/Log4jInit.class

------------------------------------------------------------------------------------

import  javax.servlet.*;
import  javax.servlet.http.*;
import  java.io.*;
import  java.util.*;

import  org.apache.Log4j.PropertyConfigurator;
import  javax.servlet.http.HttpServlet;
import  javax.servlet.http.HttpServletRequest;
import  javax.servlet.http.HttpServletResponse;
import  java.io.PrintWriter;
import  java.io.IOException;


public  class  Log4jInit  extends  HttpServlet  {
    private  static  final  String  CONTENT_TYPE  =  "text/html;  charset=EUC-KR";

    //Initialize  global  variables
    public  void  init()  throws  ServletException  {

            String  prefix  =    getServletContext().getRealPath("/");
              String  file  =  getInitParameter("Log4j-init-file");
              //  if  the  Log4j-init-file  is  not  set,  then  no  point  in  trying
              if(file  !=  null)  {
                  PropertyConfigurator.configure(prefix+file);
              }//end  if

    }//end  init

    //Process  the  HTTP  Get  request
    public  void  doGet(HttpServletRequest  request,  HttpServletResponse  response)  throws  ServletException,  IOException  {
    }

    //Process  the  HTTP  Post  request
    public  void  doPost(HttpServletRequest  request,  HttpServletResponse  response)  throws  ServletException,  IOException  {
    }

    //Clean  up  resources
    public  void  destroy()  {
    }
}
----------------------------------------------------------------------------

  

  

2.  톰켓  서버  작동시  초기화  서블릿  호출  web.xml  에  추가할  내용

      파일  경로  :  %WebApp%/WEB-INF/web.xml

------------------------------------------------------------------------------

  

    <servlet>
        <servlet-name>Log4jinit</servlet-name>
        <servlet-class>Log4jInit</servlet-class>
        <init-param>
            <param-name>Log4j-init-file</param-name>
            <param-value>WEB-INF/classes/Log4j.properties</param-value>
            <description>Log4j.properties</description>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

  

    <servlet-mapping>
        <servlet-name>Log4jinit</servlet-name>
        <url-pattern>/Log4jinit</url-pattern>
    </servlet-mapping>

  

-------------------------------------------------------------------------

  

3.  Log4j.properties  파일      (  콘솔에서  로그보이기  셋팅  )

      파일  경로  :  %WebApp%/WEB-INF/classes/Log4j.properties

-----------------------------------------------------------------------------

  

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

#  The  root  category  uses  the  appender  called  A1.  Since  no  priority  is
#  specified,  the  root  category  assumes  the  default  priority  for  root
#  which  is  DEBUG  in  Log4j.  The  root  category  is  the  only  category  that
#  has  a  default  priority.  All  other  categories  need  not  be  assigned  a
#  priority  in  which  case  they  inherit  their  priority  from  the
#  hierarchy.

#  Set  root  logger  level  to  DEBUG  and  its  only  appender  to  A1.
Log4j.rootLogger=DEBUG,  A1

#  A1  is  set  to  be  a  ConsoleAppender.
Log4j.appender.A1=org.apache.Log4j.ConsoleAppender

#  A1  uses  PatternLayout.
Log4j.appender.A1.layout=org.apache.Log4j.PatternLayout
Log4j.appender.A1.layout.ConversionPattern=%5p  [%t]  (%F:%L)  -  %m%n

  

-----------------------------------------------------------------------------

  

  

4.  Test  Application

      파일  경로  :  %WebApp%/WEB-INF/classes/InitUsingLog4jProperties.class

----------------------------------------------------------------------------

public  class  InitUsingLog4jProperties  {
        //--------------------------------------------------------------------------
        //      Constants:
        //--------------------------------------------------------------------------

        //--------------------------------------------------------------------------
        //      Protected  Variables:
        //--------------------------------------------------------------------------

        //--------------------------------------------------------------------------
        //      Private  Variables:
        //--------------------------------------------------------------------------

        private  static  Logger  logger  =
                        Logger.getLogger(InitUsingLog4jProperties.class);

        //--------------------------------------------------------------------------
        //      Constructors:
        //--------------------------------------------------------------------------

        //--------------------------------------------------------------------------
        //      Public  Methods:
        //--------------------------------------------------------------------------

        public  static  void  main(String  argv[])  {
                //  Add  a  bunch  of  logging  statements  ...
                logger.debug("Hello,  my  name  is  Homer  Simpson.");
                logger.debug("Hello,  my  name  is  Lisa  Simpson.");
                logger.debug("Hello,  my  name  is  Marge  Simpson.");
                logger.debug("Hello,  my  name  is  Bart  Simpson.");
                logger.debug("Hello,  my  name  is  Maggie  Simpson.");

                logger.info("We  are  the  Simpsons!");
                logger.info("Mmmmmm  ....  Chocolate.");
                logger.info("Homer  likes  chocolate");
                logger.info("Doh!");
                logger.info("We  are  the  Simpsons!");

                logger.warn("Bart:  I  am  through  with  working!  Working  is  for  chumps!"  +
                                "Homer:  Son,  I'm  proud  of  you.  I  was  twice  your  age  before  "  +
                                "I  figured  that  out.");
                logger.warn("Mmm...forbidden  donut.");
                logger.warn("D'oh!  A  deer!  A  female  deer!");
                logger.warn("Truly,  yours  is  a  butt  that  won't  quit."  +
                                "-  Bart,  writing  as  Woodrow  to  Ms.  Krabappel.");

                logger.error("Dear  Baby,  Welcome  to  Dumpsville.  Population:  you.");
                logger.error("Dear  Baby,  Welcome  to  Dumpsville.  Population:  you.",
                                new  IOException("Dumpsville,  USA"));
                logger.error("Mr.  Hutz,  are  you  aware  you're  not  wearing  pants?");
                logger.error("Mr.  Hutz,  are  you  aware  you're  not  wearing  pants?",
                                new  IllegalStateException("Error  !!"));


                logger.fatal("Eep.");
                logger.fatal("Mmm...forbidden  donut.",
                                new  SecurityException("Fatal  Exception"));
                logger.fatal("D'oh!  A  deer!  A  female  deer!");
                logger.fatal("Mmmmmm  ....  Chocolate.",
                                new  SecurityException("Fatal  Exception"));
        }

        //--------------------------------------------------------------------------
        //      Protected  Methods:
        //--------------------------------------------------------------------------

        //--------------------------------------------------------------------------
        //      Private  Methods:
        //--------------------------------------------------------------------------

        //--------------------------------------------------------------------------
        //      Nested  Top-Level  Classes  or  Interfaces:
        //--------------------------------------------------------------------------

}

  


-------------------------------------------------------------------------------

  

작성자  :  양승진  
LastUpdate  :  2004  /  06  /  30
메일  :  sj99yang@naver.com

블러그  :  http://blog.naver.com/sj99yang.do

[출처]  [Log4j]  Log4j  를  Tomcat  에서  사용하기...|작성자  슬레이어