Write log file using org.apache.commons.logging

前端 未结 2 680
孤独总比滥情好
孤独总比滥情好 2020-12-13 21:19

I\'m writing an application where I need to write log to a file using org.apache.commons.logging library, but i don\'t know how to start.

Can anyone hel

2条回答
  •  生来不讨喜
    2020-12-13 21:46

    I hope this helps... this is how we have done in our project...

    A. Include the jar in your project.

    B. Define log4j.xml for loggers definition something like this...

    
    
        
        
        
        
        
        
    
     
       
           
    
    
    
       
       
    
    
    
    

    C. Use the logger in the class:

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    Class YourClass{
        private static Log log = LogFactory.getLog(YourClass.class);
    
        public void yourMethod(){
            log.info("Your Message");
        }
    }
    

    EDIT: D. Since we have a JBoss AS environment so the application is configured to read log4j.xml like following (You would need an equivalent config):

    
      resource:jboss-log4j.xml
      
      true
      
      60
    
    

提交回复
热议问题