查找Log4J日志文件 [英] Finding Log4J log file

查看:164
本文介绍了查找Log4J日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个通过Commons使用Log4J的项目。

I'm working on a project that uses Log4J via Commons.

我正在尝试找到日志文件的路径,但我找不到一个适当的方法,它将从Logger返回日志文件路径。

I'm trying to find the path to the log file, but I'm not finding an appropriate method that will return the logfile path from the Logger.

有人试过这个吗?

推荐答案

您必须从根记录器获取所有appender ,然后获取日志文件的名称。

You have to get all appenders from the root logger and then get the name of the log file.

    Enumeration e = Logger.getRootLogger().getAllAppenders();
    while ( e.hasMoreElements() ){
      Appender app = (Appender)e.nextElement();
      if ( app instanceof FileAppender ){
        System.out.println("File: " + ((FileAppender)app).getFile());
      }
    }

这篇关于查找Log4J日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆