简体   繁体   中英

How do I set Priority for root logger in Spring MVC?

I am completely new to log4j. I have seen that there are two tags and tags, which refer to various appenders. As suggested by one of the link ie why do we need root and logger in log4j.xml "The only exception is the root logger that logs messages for the all classes in the application." I am using that(root logger).

In my case, I have to log all exceptions having level error to my external file. So I have used

<!-- Root Logger -->
<root>
    <priority value="error" />
    <appender-ref ref="console" />
    <appender-ref ref="FILE" />
</root>

but in my log file I am still able to see the info logger messages. I have to log only error messages, so please suggest to me what the solution might be, so I can correct it if I am wrong.

This is from the log4j manual:

If a given logger is not assigned a level, then it inherits one from its closest ancestor with an assigned level. More formally:

Level Inheritance The inherited level for a given logger C, is equal to the first non-null level in the logger hierarchy, starting at C and proceeding upwards in the hierarchy towards the root logger.

Basically, what this means is that the root logger level will only be used in the case where there are no other assigned logger levels.

For example, you may have other loggers in your xml file such as Application Loggers and 3rd Party loggers. These will override the root logger level for any classes that use them (such as your application and the spring framework). If you set all loggers to error, then errors are all you should be seeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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