简体   繁体   English

在服务器上打印System.out.println

[英]System.out.println printing on Server

Using eclipse : 使用eclipse:

When we normally sysout anything in a java file, it prints at the eclipse console but when our application is deployed on Jboss then sysout prints the value at Server console and server logs. 通常,当我们对Java文件中的所有内容进行sysout时,它将在eclipse控制台上打印,但是当我们的应用程序部署在Jboss上时,则sysout会在Server控制台和服务器日志上打印该值。 What is it, that makes this change? 这是什么,这会导致更改?

For eg: In a standalone normal Java Program 例如:在独立的普通Java程序中

System.out.println("Java is Wonderful") prints on eclipse console System.out.println("Java is Wonderful")在Eclipse控制台上打印

But if i write the same sentence in a java file ie a part of a web application and that application is deployed on JBoss then the value is printed on JBoss console and server logs. 但是,如果我在Java文件(即Web应用程序的一部分)中写相同的句子,并且该应用程序部署在JBoss上,则该值将打印在JBoss控制台和服务器日志上。

What i know is "out" refers to system console so if i sysout anything it should write to system's console. 我所知道的是“输出”是指系统控制台,因此,如果我对系统进行任何设置,都应将其写入系统控制台。 Then why in case of web application deployed on JBoss it write on Server console. 然后,为什么要在JBoss上部署Web应用程序,则将其写在Server控制台上。

The value of System.out starts out as the "standard output" stream for the JVM that is running the application. System.out的值以运行应用程序的JVM的“标准输出”流开头。

  • When you run an application within Eclipse, Eclipse has used System.setOut(...) to a stream that writes to the Eclipse console. 在Eclipse中运行应用程序时,Eclipse已将System.setOut(...)用于写入Eclipse控制台的流。

  • When you launch a JVM from Eclipse, that JVM's System.out will start out referring back to the Eclipse console. 当您从Eclipse启动JVM时,该JVM的System.out将开始回溯到Eclipse控制台。 The application in the JVM could then change it using System.setOut(...) . 然后,JVM中的应用程序可以使用System.setOut(...)对其进行更改。

  • When you launch a JVM from the command line, JVM's System.out will start out referring back to the shell's console. 当您从命令行启动JVM时,JVM的System.out将重新开始引用外壳程序的控制台。

  • For something like JBoss, it is likely that the launch script (or native launcher) will change the standard output stream before it launches the application. 对于JBoss之类的东西,启动脚本(或本机启动器)可能会启动应用程序之前更改标准输出流。 It should be documented somewhere ... 它应该记录在某处...


So to find out exactly what is going on, you will need to look at how you are launching JBoss. 因此,要弄清楚到底发生了什么,您将需要查看如何启动JBoss。

But there is nothing particularly mysterious about it. 但是,这没有什么特别神秘的。

Your server's start script probably contains something like ...> stdout.txt 2> stderr.txt or ...> allout.txt 2>&1 . 您服务器的启动脚本可能包含诸如...> stdout.txt 2> stderr.txt...> allout.txt 2>&1 It redirects standart IO in unix-like opearating systems. 它将在类似Unix的操作系统中重定向标准IO。 Other operating systems have similar commands. 其他操作系统具有类似的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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