java在异常处理(catch)中生成日志

public class LoggingException2 {
    private static Logger logger=Logger.getLogger("LoggingException2");
    static void logException(Exception e){
        StringWriter trace=new StringWriter();
        e.printStackTrace(new PrintWriter(trace));
        logger.severe(trace.toString());
    }
    public static void main(String[] args){
        try {
            throw new NullPointerException();
        }catch (NullPointerException e){
            logException(e);
        }
    }
}

你可能感兴趣的:(语言)