문제

How can i get log4j to log to a file on application exit. currently i am using the below when application is starting, but not sure how to capture on application exit

logger.info("Starting application....");
도움이 되었습니까?

해결책 2

You'll have to register a shutdown hook

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {            
    @Override
    public void run() {
        // do your thing
    }
}));

Note that this will only get executed if the program ends naturally.

다른 팁

Use a shutdown hook:

Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() {
        // log here
    });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top