0

let's start coding:

@Startup 
@Singleton
import org.apache.log4j.Logger;
public class MyClass{

    public static final Logger logger = Logger.getLogger(MyClass.class.getSimpleName());

    @PostConstruct
    private void invoke() {
        LOG.info("INFO");
        LOG.warn("WARN");
        LOG.error("ERROR");
        LOG.fatal("FATAL");
        LOG.debug("DEBUG");
        LOG.trace("TRACE");
        }
}

and if I change:

     <root-logger> <level name="INFO"/>...</root-logger> to   "DEBUG" instead of "INFO"

I have debug console. everything works fine.

now I want to change something.

I want generally root-logger to be "INFO". but with X.Y.Z package to be "DEBUG";

something like that, but it does not working:

<logger category="XXX.YYY.ZZZ" use-parent-handlers="false">
            <level name="DEBUG"/>
            </logger>
            <root-logger>
                <level name="INFO"/>
                <handlers>
                    <handler name="CONSOLE"/>
                    <handler name="FILE"/>
                </handlers>
            </root-logger>

In the other words. I only want to debug XXX.YYY.ZZZ package. not another packages ("INFO" for another packages). may be I need some filters or exception.

this XML does not works because hierarchy order of log4j is that:

OFF       <------ PERMITED
FATAL     <------ PERMITED
ERROR     <------ PERMITED
WARN      <------ PERMITED
INFO      <-----  COSTUME LOGGING PERMITTED UP TO INFO (if root-logger is "INFO)
DEBUG
TRACE
ALL

if my root-logger is "INFO" then have permission only to create costume logging to current package with hierarchy UP TO INFO

but I need some exception or something like that. I don't need any XML configuration file or properties file. I need only to change standlone.xml

4

1 回答 1

0

您正在设置use-parent-handlersto false,但您的记录器上没有安装任何处理程序。您需要将值更改为true或将处理程序添加到您的记录器。

将 设置use-parent-handlers为 false 仅使用附加到特定记录器的处理程序。由于您没有附加任何处理程序,因此没有将输出记录到的处理程序。

在您的示例中,您使用的是类的简单名称,这意味着类别MyClass不是包名称。

尝试类似:

<logger category="MyClass">
    <level name="DEBUG"/>
</logger>
于 2013-04-16T00:30:50.073 回答