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

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

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

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

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

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

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.2.RELEASE) -- ::19.899 INFO --- [ main] c.w.o.dianyixia.DianyixiaApplication : Starting DianyixiaApplication v0.0.1-SNAPSHOT on VM_0_14_centos with PID (/home/prize/dianyixia-0.0.-SNAPSHOT.jar started by prize in /home/prize)
-- ::19.905 INFO --- [ main] c.w.o.dianyixia.DianyixiaApplication : No active profile set, falling back to default profiles: default
-- ::22.500 INFO --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): (http)
-- ::22.531 INFO --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
-- ::22.531 INFO --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.]
-- ::22.711 INFO --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
-- ::22.711 INFO --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in ms
-- ::24.099 INFO --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
-- ::24.552 INFO --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): (http) with context path ''
-- ::24.555 INFO --- [ 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.-SNAPSHOT.jar > log/prize.log &
[]
[prize@centos ~]$ nohup: ignoring input and redirecting stderr to stdout

  

  看看

[prize@centos ~]$ tail -f log/prize.log
...]
-- ::34.186 INFO --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3..Final}
-- ::34.192 INFO --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
-- ::34.672 INFO --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0..Final}
-- ::35.340 INFO --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
-- ::36.980 INFO --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
-- ::38.777 INFO --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
-- ::38.901 WARN --- [ 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
-- ::39.474 INFO --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): (http) with context path ''
-- ::39.480 INFO --- [ main] com.wlf.order.prize.PrizeApplication : Started PrizeApplication in 12.758 seconds (JVM running for 13.763)
上一篇:log4.net 自定义日志文件名称


下一篇:权限问题导致zabbix无法监控mysql