简体   繁体   English

Spring 开机读取日志

[英]Spring boot read logs

I have a Java11 Spring Boot application, and an old Java8 Struts1 application.我有一个 Java11 Spring 引导应用程序和一个旧的 Java8 Struts1 应用程序。

Is it possible for the Struts1 application to read the console output logs generated by the Spring Boot application? Struts1 应用程序是否可以读取由 Spring 引导应用程序生成的控制台 output 日志?

(I think the answer is it is not possible, but hoping there may be a way) (我认为答案是不可能的,但希望有办法)

when a logger object prints to console, it is writing to System.out.当记录器 object 打印到控制台时,它正在写入 System.out。

System.out is a static object of class PrintStream, which is an OutputStream. System.out 是 static object 的 class PrintStream,它是一个 OutputStream。 And you cannot read from an OutputStream.而且您无法从 OutputStream 中读取。

Instead, your Spring Boot application may use a FileAppender to print to a file.log and your Struts application may read from that file.log.相反,您的 Spring 引导应用程序可以使用 FileAppender 打印到 file.log,并且您的 Struts 应用程序可以从该 file.log 中读取。

However, this looks like a quick and dirty solution.但是,这看起来像是一个快速而肮脏的解决方案。 Actually, the standard way to allows communication between Java applications is exchanging messages with JMS API.实际上,允许 Java 应用程序之间通信的标准方式是与 JMS API 交换消息。

I thinks you should use sth to keep logs that generated by struct and then read them with spring, if you want to read them in real time apache Kafka is my suggestion.我认为你应该使用 sth 来保存 struct 生成的日志,然后用 spring 读取它们,如果你想实时读取它们 apache Kafka 是我的建议。 stream logs into Kafka with struct then read them in your spring application stream 使用 struct 登录到 Kafka,然后在您的 spring 应用程序中读取它们

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

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