How to write error log or exception into file in java

后端 未结 6 570
余生分开走
余生分开走 2020-12-24 07:59

Is there any way to write error log or exception into a file in java. i have gone through Log4j. I googled about it but diidnt find a good solution. I have written a simple

6条回答
  •  执笔经年
    2020-12-24 08:57

    You can add the exception as a parameter to your log4j statement, e.g.

    catch(Exception e)
    {
        logger.error("Unexpected error", e);
    }
    

    Provided you've got a file appender running OK, this will output the complete stack trace of the exception.

提交回复
热议问题