Eclipse 写入控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1836981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse write to console
提问by drbob
In Eclipse, how can I write a debug statement to a console window? I tried:
在 Eclipse 中,如何将调试语句写入控制台窗口?我试过:
System.out.print(urls);
System.out.println(urls);
Log.d("tag", urls);
But I don't see the values being displayed anywhere.
但我没有看到任何地方显示的值。
Thanks.
谢谢。
回答by aerobiotic
Create a console and write to it. When a console is created, you give it a name. That way your console output can be kept separate from other plugin's console output. See this article for details.
创建一个控制台并写入它。创建控制台后,您可以为其命名。这样你的控制台输出可以与其他插件的控制台输出分开。有关详细信息,请参阅此文章。
http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F
http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F
回答by dcp
Are you sure you have the console window in eclipse setup to display output? On the menu bar in eclipse, go to Window->Show View->Console. When you run the program, that console window should be where your System.out.print(ln) output is displayed.
您确定在 eclipse 设置中有控制台窗口来显示输出吗?在 eclipse 的菜单栏上,转到 Window->Show View->Console。当您运行该程序时,该控制台窗口应该是您的 System.out.print(ln) 输出的显示位置。
回答by Greg Charles
If you are running some kind of client-server application, you may actually have multiple consoles. If you see a console, there should be a little arrow icon next to it. Use that to dropdown a list of all the various consoles, and pick the appropriate one.
如果您正在运行某种客户端-服务器应用程序,您实际上可能有多个控制台。如果你看到一个控制台,它旁边应该有一个小箭头图标。使用它来下拉所有各种控制台的列表,然后选择合适的一个。
回答by austin
My output goes to the LogCat tab, not the Console.
我的输出转到 LogCat 选项卡,而不是控制台。
回答by shashaDenovo
If you are running any class having main method and want to print logs on eclipse console, then create a file "log4j.properties" in src/main/resources
如果您正在运行任何具有 main 方法的类并希望在 Eclipse 控制台上打印日志,请在 src/main/resources 中创建一个文件“log4j.properties”
If you want to print log in your test classes then put this file in src/test/resources.
如果你想在你的测试类中打印日志,那么把这个文件放在 src/test/resources 中。
log4j.properties
log4j.properties
log4j.rootLogger=INFO, DEBUG, WARN, ERROR, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%C:%L] [%t] - %m%n log4j.logger.backtype.storm=DEBUG log4j.logger.clojure.tools=DEBUG
log4j.rootLogger=INFO, DEBUG, WARN, ERROR, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%C:%L] [%t] - %m%n log4j.logger.backtype.storm=DEBUG log4j.logger.clojure.tools=DEBUG
回答by user889030
try this , it will output in console tab
试试这个,它会在控制台选项卡中输出
System.out.print("Hello World ..... !");
// Redirect the stdout and stderr to the LogPanel
SystemLogger out = new SystemLogger(System.out, Level.INFO);
SystemLogger err = new SystemLogger(System.err, Level.ERROR);
System.setOut(out);
System.setErr(err);
回答by Sammy Cakes
I assume your code is in Java? If you want to use a logger that will print out to your console similarly to "system.out.println();", add java.util.logging to your eclipse project. import java.util.logging.Logger;
我假设你的代码是用 Java 编写的?如果您想使用类似于“system.out.println();”的方式打印到控制台的记录器,请将 java.util.logging 添加到您的 eclipse 项目中。import java.util.logging.Logger;
Then inside each class where you want output to your console, add private static final Logger LOG = Logger.getLogger(<your_class_name>.class.getName());
replacing with your class name.
然后在您希望输出到控制台的每个类中,添加private static final Logger LOG = Logger.getLogger(<your_class_name>.class.getName());
替换为您的类名。
And where you want console output, put a line in that part of your class like LOG.info("code got to this point!");
similarly to how you would use system.out.println();
在你想要控制台输出的地方,在你的类的那部分放一行,就像LOG.info("code got to this point!");
你如何使用 system.out.println();
I only use the logger instead of system.out.println();
statements because the logging seems more professional. And frankly the logger is less key strokes to write log.info than system.out.println, which saves time.
我只使用记录器而不是system.out.println();
语句,因为记录看起来更专业。坦率地说,记录器编写 log.info 的击键次数比 system.out.println 少,从而节省了时间。
This article is where I learned the logging info: https://examples.javacodegeeks.com/core-java/util/logging/java-util-logging-example/
这篇文章是我了解日志信息的地方:https: //examples.javacodegeeks.com/core-java/util/logging/java-util-logging-example/