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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM