简体   繁体   English

如何使用System.out.println查找Java类?

[英]How to find the Java class using System.out.println?

Logs are being redirected as SystemOut. 日志被重定向为SystemOut。 How to find the Java class printing these statements? 如何找到打印这些语句的Java类?

[7/11/19 10:34:41:786 EDT] 0000010b SystemOut O [2019-07-11 10:34:41,785] [WebContainer : 2] DEBUG loader.Loader (getRow:1533)- Result row: [7/11/19 10:34:41:786 EDT] 0000010b SystemOut O [2019-07-11 10:34:41,785] [WebContainer:2] DEBUG loader.Loader(getRow:1533)-结果行:

I want to block/suppress/remove these SystemOut statements. 我想阻止/禁止/删除这些SystemOut语句。


UPDATE added stack traces of caller of PrintStream based on this answer by dbourne. UPDATE根据dbourne的回答添加了PrintStream调用者的堆栈跟踪。

21:02:00.444 0x30004f00              mt.0        > java/io/PrintStream.println(Ljava/lang/String;)V bytecode method, this = 0x7ffa75098
21:02:00.444 0x30004f00       j9trc_aux.0        - jstacktrace:
21:02:00.444 0x30004f00       j9trc_aux.1        - [1] java.io.PrintStream.println (PrintStream.java:829)
21:02:00.444 0x30004f00       j9trc_aux.1        - [2] com.ibm.ejs.ras.hpel.HpelHelper.printHeader (HpelHelper.java:662)
21:02:00.444 0x30004f00       j9trc_aux.1        - [3] com.ibm.ejs.ras.RasHelper.printHeader (RasHelper.java:1898)
21:02:00.444 0x30004f00       j9trc_aux.1        - [4] com.ibm.ejs.ras.RasHelper.printHeader (RasHelper.java:1892)
21:02:00.444 0x30004f00       j9trc_aux.1        - [5] com.ibm.ejs.ras.SystemOutStream.replaceSystemOutStream (SystemOutStream.java:156)
21:02:00.444 0x30004f00       j9trc_aux.1        - [6] com.ibm.ws.runtime.WsServerImpl.redirectStream (WsServerImpl.java:459)
21:02:00.444 0x30004f00       j9trc_aux.1        - [7] com.ibm.ws.runtime.WsServerImpl.bootLoggingServices (WsServerImpl.java:402)
21:02:00.444 0x30004f00       j9trc_aux.1        - [8] com.ibm.ws.runtime.WsServerImpl.start (WsServerImpl.java:201)
21:02:00.444 0x30004f00       j9trc_aux.1        - [9] com.ibm.ws.runtime.WsServerImpl.main (WsServerImpl.java:697)
21:02:00.445 0x30004f00       j9trc_aux.1        - [10] com.ibm.ws.runtime.WsServer.main (WsServer.java:59)
21:02:00.445 0x30004f00       j9trc_aux.1        - [11] sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
21:02:00.445 0x30004f00       j9trc_aux.1        - [12] sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:90)
21:02:00.445 0x30004f00       j9trc_aux.1        - [13] sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:55) (Compiled Code)
21:02:00.445 0x30004f00       j9trc_aux.1        - [14] java.lang.reflect.Method.invoke (Method.java:508) (Compiled Code)
21:02:00.445 0x30004f00       j9trc_aux.1        - [15] com.ibm.wsspi.bootstrap.WSLauncher.launchMain (WSLauncher.java:234)
21:02:00.445 0x30004f00       j9trc_aux.1        - [16] com.ibm.wsspi.bootstrap.WSLauncher.main (WSLauncher.java:101)
21:02:00.445 0x30004f00       j9trc_aux.1        - [17] com.ibm.wsspi.bootstrap.WSLauncher.run (WSLauncher.java:82)
21:02:00.445 0x30004f00       j9trc_aux.1        - [18] sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
21:02:00.445 0x30004f00       j9trc_aux.1        - [19] sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:90)
21:02:00.445 0x30004f00       j9trc_aux.1        - [20] sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:55) (Compiled Code)
21:02:00.445 0x30004f00       j9trc_aux.1        - [21] java.lang.reflect.Method.invoke (Method.java:508) (Compiled Code)
21:02:00.445 0x30004f00       j9trc_aux.1        - [22] org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException (EclipseAppContainer.java:587)
21:02:00.445 0x30004f00       j9trc_aux.1        - [23] org.eclipse.equinox.internal.app.EclipseAppHandle.run (EclipseAppHandle.java:198)
21:02:00.445 0x30004f00       j9trc_aux.1        - [24] org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication (EclipseAppLauncher.java:110)
21:02:00.445 0x30004f00       j9trc_aux.1        - [25] org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start (EclipseAppLauncher.java:79)
21:02:00.445 0x30004f00       j9trc_aux.1        - [26] org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:354)
21:02:00.445 0x30004f00       j9trc_aux.1        - [27] org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:181)
21:02:00.445 0x30004f00       j9trc_aux.1        - [28] sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
21:02:00.445 0x30004f00       j9trc_aux.1        - [29] sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:90)
21:02:00.445 0x30004f00       j9trc_aux.1        - [30] sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:55)
21:02:00.445 0x30004f00       j9trc_aux.1        - [31] java.lang.reflect.Method.invoke (Method.java:508)
21:02:00.445 0x30004f00       j9trc_aux.1        - [32] org.eclipse.core.launcher.Main.invokeFramework (Main.java:340)
21:02:00.445 0x30004f00       j9trc_aux.1        - [33] org.eclipse.core.launcher.Main.basicRun (Main.java:282)
21:02:00.445 0x30004f00       j9trc_aux.1        - [34] org.eclipse.core.launcher.Main.run (Main.java:981)
21:02:00.445 0x30004f00       j9trc_aux.1        - [35] com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse (WSPreLauncher.java:413)
21:02:00.445 0x30004f00       j9trc_aux.1        - [36] com.ibm.wsspi.bootstrap.WSPreLauncher.main (WSPreLauncher.java:174)
21:02:00.446 0x30004f00              mt.6        < java/io/PrintStream.println(Ljava/lang/String;)V bytecode method
.
.
.
02:09:27.893 0x33dd3000              mt.1        > java/io/PrintStream.println(Ljava/lang/String;)V compiled method, this = 0x700d16a70
02:09:27.893 0x33dd3000       j9trc_aux.0        - jstacktrace:
02:09:27.893 0x33dd3000       j9trc_aux.1        - [1] java.io.PrintStream.println (PrintStream.java:829) (Compiled Code)
02:09:27.893 0x33dd3000       j9trc_aux.1        - [2] com.ibm.ejs.ras.SystemStream.writeWebSphereEvent (SystemStream.java:738) (Compiled Code)
02:09:27.893 0x33dd3000       j9trc_aux.1        - [3] com.ibm.ejs.ras.SystemOutStream.logMessage (SystemOutStream.java:330) (Compiled Code)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [4] com.ibm.ejs.ras.SystemOutStream.processEvent (SystemOutStream.java:319) (Compiled Code)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [5] com.ibm.ws.logging.WsHandlerWrapper.publish (WsHandlerWrapper.java:43)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [6] java.util.logging.Logger.log (Logger.java:749) (Compiled Code)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [7] com.ibm.ws.logging.WsLogger.deliverOrBuffer (WsLogger.java:416)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [8] com.ibm.ws.logging.WsLogger.log (WsLogger.java:394)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [9] com.ibm.ws.logging.WsLogger.logp (WsLogger.java:599) (Compiled Code)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [10] org.apache.commons.logging.impl.Jdk14Logger.log (Jdk14Logger.java:126)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [11] org.apache.commons.logging.impl.Jdk14Logger.info (Jdk14Logger.java:193)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [12] org.springframework.context.support.AbstractApplicationContext.initMessageSource (AbstractApplicationContext.java:473)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [13] org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:334)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [14] org.springframework.context.support.ClassPathXmlApplicationContext.<init> (ClassPathXmlApplicationContext.java:92)
02:09:27.894 0x33dd3000       j9trc_aux.1        - [15] org.springframework.context.support.ClassPathXmlApplicationContext.<init> (ClassPathXmlApplicationContext.java:77)
.
.
.

If you have the source code, I would suggest something like grep "System.out" over the whole source tree. 如果您有源代码,我建议在整个源代码树中使用类似grep "System.out"的名称。

Another approach could be to write an implementation of PrintStream that dumps a stack trace to the console each time it is called. 另一种方法可能是编写PrintStream的实现,该实现在每次调用时都将堆栈跟踪信息转储到控制台。 Then write a wrapper class that sets an instance of that new PrintStream for out ( System.setOut( new MyPrintStream( System.out ) ) ) before it calls main() of your program's main class. 然后编写一个包装器类,在调用程序的主类的main()之前,将该新PrintStream的实例设置为outSystem.setOut( new MyPrintStream( System.out ) ) )。

You can implement MyPrintStream in a way that it will only print a caller once, and only the line that holds the out.print*() statement. 您可以通过以下方式实现MyPrintStream ,使其仅打印一次调用者,并且仅打印包含out.print*()语句的行。 But however, you have to make sure that the program will execute all branches to be sure that all locations will be printed. 但是,您必须确保该程序将执行所有分支,以确保将打印所有位置。

The IBM JDK provides a tracing facility that you can use to find who is calling any method. IBM JDK提供了一种跟踪工具,您可以使用它来查找谁正在调用任何方法。 To find who is calling System.out.println, add the following to your genericJvmArguments and restart the server. 要查找谁在调用System.out.println,请将以下内容添加到您的genericJvmArguments中,然后重新启动服务器。 The output, which will show a stack trace of the caller, should appear in your native_stdout.log file. 输出将显示调用方的堆栈跟踪,该输出应显示在native_stdout.log文件中。

-Xtrace:print=mt,trigger=method{java/io/PrintStream.println,jstacktrace}

A snippet of the stack trace for a sample application, which calls System.out.println(), with the above JVM argument set, which identifies that the Hello.printHello (Hello.java:15) writes to System.out. 带有上面的JVM参数集的示例应用程序的堆栈跟踪的片段,调用System.out.println(),标识了Hello.printHello(Hello.java:15)写入System.out。

03:41:01.245*0x3277900 mt.0 > java/io/PrintStream.println(Ljava/lang/String;)V Bytecode method, This = 7fffff49f98
03:41:01.247 0x3277900 j9trc_aux.0 - jstacktrace:
03:41:01.248 0x3277900 j9trc_aux.1 - [1] java.io.PrintStream.println (PrintStream.java:829)
03:41:01.248 0x3277900 j9trc_aux.1 - [2] com.ibm.jvm.io.ConsolePrintStream.println (ConsolePrintStream.java:311)
03:41:01.250 0x3277900 j9trc_aux.1 - [3] Hello.printHello (Hello.java:15)
03:41:01.251 0x3277900 j9trc_aux.1 - [4] Hello.main (Hello.java:9)Hello World
03:41:01.253 0x3277900 mt.6 < java/io/PrintStream.println(Ljava/lang/String;)V Bytecode method

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

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