相关疑难解决方法(0)

在使用java logging API时,如何禁用默认控制台处理程序?

嗨,我正在尝试在我的应用程序中实现java日志记录.我想使用两个处理程序.文件处理程序和我自己的控制台处理程序 我的两个处理程序都运行良好.我的日志记录将发送到文件和控制台.我的日志记录也被发送到我不想要的默认控制台处理程序.如果您运行我的代码,您将看到发送到控制台的额外两行.我不想使用默认的控制台处理程序.有谁知道如何禁用默认控制台处理程序.我只想使用我创建的两个处理程序.

Handler fh = new FileHandler("test.txt");
fh.setFormatter(formatter);
logger.addHandler(fh);
Run Code Online (Sandbox Code Playgroud)
Handler ch = new ConsoleHandler();
ch.setFormatter(formatter);
logger.addHandler(ch);
Run Code Online (Sandbox Code Playgroud)
import java.util.Date;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

public class LoggingExample {
    private static Logger logger = Logger.getLogger("test");

    static {
        try {
            logger.setLevel(Level.INFO);

            Formatter formatter = new Formatter() {

                @Override
                public String format(LogRecord arg0) {
                    StringBuilder b = new StringBuilder();
                    b.append(new Date());
                    b.append(" ");
                    b.append(arg0.getSourceClassName());
                    b.append(" ");
                    b.append(arg0.getSourceMethodName());
                    b.append(" ");
                    b.append(arg0.getLevel());
                    b.append(" ");
                    b.append(arg0.getMessage()); …
Run Code Online (Sandbox Code Playgroud)

java java.util.logging

89
推荐指数
5
解决办法
10万
查看次数

Tomcat STDOUT as Error in Eclipse

I am configuring Tomcat (5.5) server in Eclipse (3.3.2). Once I add Tomcat and start it, the output is printed in Eclipse Console. This output is printed in RED indicating its Standard Error. Although the server gets started without any error the normal INFO is also marked as error.

Jul 29, 2010 7:06:14 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_10\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.5.0_10\bin\..\jre\bin\client;C:\Program …
Run Code Online (Sandbox Code Playgroud)

eclipse tomcat

22
推荐指数
1
解决办法
4980
查看次数

为什么java.util.logging.Logger打印到stderr?

我有一个简单的设置来记录消息:JDK 8 Update 65和Eclipse Mars

import java.util.logging.Logger;

public class Example {

    private final static Logger LOGGER = Logger.getLogger(Example.class.getName());

    public static void main(String[] args) {
        LOGGER.info("Test");
    }

}
Run Code Online (Sandbox Code Playgroud)

我希望得到一个输出stdout,就像使用一样System.out.println();.
但它会打印出来stderr,这会在eclipse控制台上产生一个红色字体:

在此输入图像描述

我知道我可以通过编写自定义来改变这种行为Handler,但我想知道为什么默认输出会出现在?stderr而不是stdout?

记录器应该stdout用于fine+ info并stderr用于severe级别.

java eclipse logging stderr java.util.logging

11
推荐指数
2
解决办法
5167
查看次数

标签 统计

eclipse ×2

java ×2

java.util.logging ×2

logging ×1

stderr ×1

tomcat ×1