linux后台启动springboot并指定日志文件名称

Posted 不想下火车的人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux后台启动springboot并指定日志文件名称相关的知识,希望对你有一定的参考价值。

  如果用nohup启动jar包的话,默认的日志文件就是nohup.out,那么如果启动多个jar包的话,看日志文件就麻烦了,因为他们都会写入到nohup.out文件中。

  所以我们来指定一下不同jar包的日志文件名:

[prize@centos ~]$ mkdir log
[prize@centos ~]$ nohup java -jar dianyixia-0.0.1-SNAPSHOT.jar > log/dianyixia.log &
[1] 5861
[prize@centos ~]$ nohup: ignoring input and redirecting stderr to stdout

 

  看一眼,日志确实写入到dianyixia.log文件中了:

[prize@centos ~]$ cat log/dianyixia.log 

  .   ____          _            __ _ _
 /\ / ____ __ _ _(_)_ __  __ _    
( ( )\___ | _ | _| | _ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
    |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)

2019-12-23 11:37:19.899  INFO 5861 --- [           main] c.w.o.dianyixia.DianyixiaApplication     : Starting DianyixiaApplication v0.0.1-SNAPSHOT on VM_0_14_centos with PID 5861 (/home/prize/dianyixia-0.0.1-SNAPSHOT.jar started by prize in /home/prize)
2019-12-23 11:37:19.905  INFO 5861 --- [           main] c.w.o.dianyixia.DianyixiaApplication     : No active profile set, falling back to default profiles: default
2019-12-23 11:37:22.500  INFO 5861 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9998 (http)
2019-12-23 11:37:22.531  INFO 5861 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-12-23 11:37:22.531  INFO 5861 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]
2019-12-23 11:37:22.711  INFO 5861 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-12-23 11:37:22.711  INFO 5861 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2672 ms
2019-12-23 11:37:24.099  INFO 5861 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService applicationTaskExecutor
2019-12-23 11:37:24.552  INFO 5861 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9998 (http) with context path ‘‘
2019-12-23 11:37:24.555  INFO 5861 --- [           main] c.w.o.dianyixia.DianyixiaApplication     : Started DianyixiaApplication in 5.653 seconds (JVM running for 6.653)

 

  如法炮制,再来一个:

[prize@centos ~]$ nohup java -jar prize-0.0.1-SNAPSHOT.jar > log/prize.log &
[2] 6306
[prize@centos ~]$ nohup: ignoring input and redirecting stderr to stdout

  

  看看

[prize@centos ~]$ tail -f log/prize.log 
        ...]
2019-12-23 11:40:34.186  INFO 6306 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.10.Final}
2019-12-23 11:40:34.192  INFO 6306 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-12-23 11:40:34.672  INFO 6306 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-12-23 11:40:35.340  INFO 6306 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.mysql5Dialect
2019-12-23 11:40:36.980  INFO 6306 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit default
2019-12-23 11:40:38.777  INFO 6306 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService applicationTaskExecutor
2019-12-23 11:40:38.901  WARN 6306 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-12-23 11:40:39.474  INFO 6306 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9988 (http) with context path ‘‘
2019-12-23 11:40:39.480  INFO 6306 --- [           main] com.wlf.order.prize.PrizeApplication     : Started PrizeApplication in 12.758 seconds (JVM running for 13.763)

 

以上是关于linux后台启动springboot并指定日志文件名称的主要内容,如果未能解决你的问题,请参考以下文章

linux服务器部署SpringBoot项目并查看项目运行日志

springboot之jar包Linux后台启动部署及滚动日志查看且日志输出至文件保存(超级详细)

linux后台运行springboot项目

nohup 后台启动程序,并输出到指定日志

Linux 更加优雅地运行 JAR 文件,并将日志文件输出到本地目录,并优雅的查看日志文件信息

项目部署