log4j2为某个类某个方法单独文件打印日志,定时删除日志

log4j2.xml配置




    
    
        
        
        ${sys:catalina.home}/logs/webchat
        %d{yyyy-MM-dd}-%i.gz
        10MB
        %d{yyyy-MM-dd HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n
    

    
    
        
        
            
            
            
           
        

        
        
        
            
            
        

        
        
            
            
        

        

        
            

            
                
                
                
            

            
                
                    
                    
                
            

        

    
    
    
        
        
            
            
        
        
        
            
            
        
        
            
        
    


java类中代码片段如下

@Controller
@RequestMapping("/login")
public class LoginController extends BaseController{

    static Logger sendCodeLogger = LogManager.getLogger("sendCodeLogger");

@RequestMapping(value = "/sendCode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public String sendCode(String phone,HttpServletRequest request) {

    String result = "error";

    try {
        String ip = CommonUtil.getRemoteIp(request);
        sendCodeLogger.info("###################ip为: "+ip);

        Enumeration em = request.getParameterNames();
        sendCodeLogger.info("###################开始记录手机验证码接口中的HttpServletRequest.getParameterNames");
        while (em.hasMoreElements()) {
            String name = (String) em.nextElement();
            String value = request.getParameter(name);
            sendCodeLogger.info("getParameter参数:"+name+" = "+value);
        }
        sendCodeLogger.info("###################结束记录getParameter参数");
       ...

你可能感兴趣的:(log4j2为某个类某个方法单独文件打印日志,定时删除日志)