问题描述
赦免问题太微不足道.我是Log4J的新手.我已经看到有两个标签和标签,它们是指各种附录. 说我想在文件库中记录信息,将其发送到我的电子邮件中,然后将其打印到控制台.我希望将级别设置为信息.有一个对三个附录的引用的单个标签(文件,电子邮件和控制台),为什么我们需要另一个标签?
推荐答案
就足够了.
log4j中的记录器与软件包或有时与特定类关联. Logger的软件包/类由属性"名称"定义. Logger在其软件包中以及所有子包及其课程中都会记录消息.唯一的例外是登录应用程序中所有类的消息的根记录器.
记录仪也具有水平,并且可能附有一个或多个附属(记录目的地).
在下一个示例中,我们有两个记录器:
- 将消息与级别登录级别或以上包含的所有软件包中的根记录器到各个目的地:控制台,电子邮件和文件,
- " com.foo"记录器,该记录器将消息登录级别的evaln或package" com.foo"及其子套件中的级别.
<log4j:configuration> <!-- Declaration of appenders FILE, MAIL, CONSOLE and ANOTHERFILE --> ... <!-- --> <logger name="com.foo"> <level value="warn"/> <appender-ref ref="ANOTHERFILE" /> </logger> <root> <priority value ="info" /> <appender-ref ref="FILE" /> <appender-ref ref="MAIL" /> <appender-ref ref="CONSOLE" /> </root> </log4j:configuration>
问题描述
pardon if the question is too trivial. I am completely new to log4j. I have seen that there are two tags and tags, which refer to various appenders. Say i want to log the information in my code base in a file, send it to my email and print it to console. I want the level set to info. Isnt it enough to have a single tag which has references to the three appenders ?( file, email and the console) why do we need another for the same ?
推荐答案
It is enough.
In log4j a logger is associated with a package or sometimes with a particular class. Package/class of a logger is defined by the attribute "name". A logger logs messages in its package and also in all the child packages and their classes. The only exception is the root logger that logs messages for the all classes in the application.
A logger also has level and may have one or many appenders (logging destinations) attached to it.
In the next example we have two loggers:
- the root logger that logs messages with level INFO or above in the all packages to the various destinations: console, e-mail and file,
- "com.foo" logger that logs messages with level WARN or above in package "com.foo" and its child packages to the another file.
<log4j:configuration> <!-- Declaration of appenders FILE, MAIL, CONSOLE and ANOTHERFILE --> ... <!-- --> <logger name="com.foo"> <level value="warn"/> <appender-ref ref="ANOTHERFILE" /> </logger> <root> <priority value ="info" /> <appender-ref ref="FILE" /> <appender-ref ref="MAIL" /> <appender-ref ref="CONSOLE" /> </root> </log4j:configuration>
You should read more about the log4j basics.