简体   繁体   English

如何在spring启动应用程序中的.log文件中编写stdout语句

[英]How to write a stdout statement in a .log file in spring boot application

  • I am trying to write System.out.print statement in log file 我试图在日志文件中编写System.out.print语句

  • I use the following application.properties file 我使用以下application.properties文件

logging.level.org.springframework.web=INFO logging.level.org.springframework.web = INFO

logging.level.org.hibernate=ERROR logging.level.org.hibernate = ERROR

logging.level.com.cirq.configurator=INFO logging.level.com.cirq.configurator = INFO

logging.path=${mypath} logging.path = $ {mypath中}

logging.file=filename.log logging.file = filename.log

  • But using the above code, I am not able to write System.out.print statement in the log file 但是使用上面的代码,我无法在日志文件中编写System.out.print语句
  • First, I create .jar file of my spring-boot project and run in undertow application server 首先,我创建spring-boot项目的.jar文件并在underow应用程序服务器中运行
  • Please help me.... Thanks in advance 请帮帮我....先谢谢

if you are deploying .jar file in undertow application server, then System.out.print statement will not work(means it will not write in log file). 如果要在下载应用程序服务器中部署.jar文件,则System.out.print语句将不起作用(表示它不会写入日志文件中)。

For that you have to use log4j which is in-built in Spring Boot. 为此,你必须使用在Spring Boot中内置的log4j。

Example: 例:

final static Logger logger = LoggerFactory.getLogger(YourController.class);

logger.info("Your print statement");

Refer link 参考链接

You need to add this dependency in your pom.xml file: 您需要在pom.xml文件中添加此依赖项:

<dependency>
   <groupId>uk.org.lidalia</groupId>
   <artifactId>sysout-over-slf4j</artifactId>
   <version>1.0.2</version>
</dependency>

Then in the main method before you do anything call this code: 然后在main方法执行任何操作之前调用此代码:

SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();

That way anything that is written in sysout or syserr gets caught in the logging system 这样,在sysout或syserr中编写的任何内容都会被记录在系统中

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

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