配置 log4j 时遇到问题
我在 Win XP 和 log4j 1.2.12 上使用 Java 6。我在将日志输出到文件时遇到问题(没有出现 log4j.log)。下面是我的 log4j.properties 配置,它出现在我的 war 的 WEB-INF/classes 目录中...
log4j.rootLogger=DEBUG, A2
log4j.appender.A1 = org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout = org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
log4j.appender.A2 = org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.File = c:\apache-tomcat-6.0.33\logs\log4j.log
log4j.appender.A2.Append = true
log4j.appender.A2.DatePattern = '.'yyy-MM-dd
log4j.appender.A2.layout = org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
这是我如何访问我的类中的记录器...
public class XMLNode {
private static Logger logger = Logger.getLogger(XMLNode.class);
...
logger.debug("test:" + main.toString());
任何其他想法我还应该做什么或检查来获取我的 log4j。属性文件出现吗?谢谢,-戴夫
I'm using Java 6 on Win XP and log4j 1.2.12. I'm having trouble getting my logs output to a file (no log4j.log appears). Below is my log4j.properties config, which appears in my war's WEB-INF/classes directory ...
log4j.rootLogger=DEBUG, A2
log4j.appender.A1 = org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout = org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
log4j.appender.A2 = org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.File = c:\apache-tomcat-6.0.33\logs\log4j.log
log4j.appender.A2.Append = true
log4j.appender.A2.DatePattern = '.'yyy-MM-dd
log4j.appender.A2.layout = org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
And here's how I access the logger in my class ...
public class XMLNode {
private static Logger logger = Logger.getLogger(XMLNode.class);
...
logger.debug("test:" + main.toString());
Any other ideas what else I should do or check to get my log4j.properties file to appear? Thanks, - Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题似乎与文件名的格式有关。
您需要更改文件路径以使用正斜杠(
/
)或双反斜杠(\\
)我运行了上面的示例,当我更改文件时路径它工作得很好。
Your problem appears to be with the format of the file name.
You will need to change the file path to use either forward slashes (
/
) or double back slashes (\\
)I ran your example above, and when I changed the file path it worked fine.
使用直接 LOGGER.info(String-Message).. 希望您能获得日志文件..
我认为您的日志文件存在,但您没有在正确的位置搜索它..找到它
use direct LOGGER.info(String-Message).. hope so you will get the log file..
i think your log file is present but you are not searching it at right place.. find it in