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

查看:60
本文介绍了查找 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天全站免登陆