简体   繁体   English

使用记录器配置类以使用log4j登录到文件

[英]Configuring a class using a logger to log to a file with log4j

Hi I have 4 classes that each share anonymous instances of a logger class (not my creation). 嗨,我有4个类,每个类共享一个记录器类的匿名实例(不是我的创作)。 I have added a log4j appender and set the logger to log to the appender file. 我添加了一个log4j附加程序,并将记录器设置为登录到附加程序文件。 The problem is that everything is logging to the file including Hibernate. 问题是所有内容都记录到了包括Hibernate在内的文件中。 How do I set up the classes only to log to this file? 如何设置仅登录此文件的类?

Here is my present configuration file: 这是我目前的配置文件:

# Direct log messages to a file
log4j.appender.file=com.daniels.logging.RollingFileAppender
log4j.appender.file.File=daniels.log
log4j.appender.file.MaxFileSize=100MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.S} %-5p [%c{1}:%M] - %m%n
log4j.appender.file.append=true

# Root logger option
log4j.rootLogger=INFO, file

One of my classes is called SeriousEvent. 我的一门课叫作“严重事件”。 If I would like this class to log to the file com.daniels.logging.RollingFileAppender how would I set this up? 如果我希望此类记录到com.daniels.logging.RollingFileAppender文件,我将如何设置它? I'm new to logging so forgive me. 我是伐木新手,请原谅我。 I have looked through the documentation but I'm finding it hard getting a good example. 我仔细阅读了文档,但是很难找到一个好的例子。

Thanks, Daniel 谢谢,丹尼尔

I think those links below can help you: 我认为以下链接可以为您提供帮助:

You also might see the Log4j documentation page in order to understand the appenders. 您也可能会看到Log4j文档页面 ,以了解附加程序。

One question: did you develop a customized appender for your system? 一个问题:您是否为系统开发了定制的附加程序? I'm asking that because you added on your file: 我问这是因为您在文件中添加了:

log4j.appender.file=com.daniels.logging.RollingFileAppender

Seeing on log4j docs, this property should be and component appender, such as: 看到log4j文档,此属性应该是和组件追加程序,例如:

log4j.appender.file=org.apache.log4j.RollingFileAppender

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM