簡體   English   中英

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

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

日志被重定向為SystemOut。 如何找到打印這些語句的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)-結果行:

我想阻止/禁止/刪除這些SystemOut語句。


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)
.
.
.

如果您有源代碼,我建議在整個源代碼樹中使用類似grep "System.out"的名稱。

另一種方法可能是編寫PrintStream的實現,該實現在每次調用時都將堆棧跟蹤信息轉儲到控制台。 然后編寫一個包裝器類,在調用程序的主類的main()之前,將該新PrintStream的實例設置為outSystem.setOut( new MyPrintStream( System.out ) ) )。

您可以通過以下方式實現MyPrintStream ,使其僅打印一次調用者,並且僅打印包含out.print*()語句的行。 但是,您必須確保該程序將執行所有分支,以確保將打印所有位置。

IBM JDK提供了一種跟蹤工具,您可以使用它來查找誰正在調用任何方法。 要查找誰在調用System.out.println,請將以下內容添加到您的genericJvmArguments中,然后重新啟動服務器。 輸出將顯示調用方的堆棧跟蹤,該輸出應顯示在native_stdout.log文件中。

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

帶有上面的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