Get the App
SLTechnology News&Howtos  ›  Development  › 

How to start and configure log files using SpringBoot_jar

Shulou Source: shulou.com Published: 2022-06-03 20:12:58 09月13日 Update

Editor to share with you how to use SpringBoot_jar to start and configure log files, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Start and configure log file preface in SpringBoot_jar mode

To start normally, the default startup file configured in application.properties will be selected to start. The following situation cannot start the project according to the actual situation.

Java jar admin-1.0-SNAPSHOT.jar

1. Test environment and production environment startup

Mainly observe the name of the configuration file in priperties

Test environment: java-jar my-spring-boot.jar-- spring.profiles.active=test

Production environment: java-jar my-spring-boot.jar-spring.profiles.active=prod

2. Launch and configure log log 2.1with shell, launch test library #! / bin/bash echo starting java-jar admin-1.0-SNAPSHOT.jar-- spring.profiles.active=test > log.file 2 > log.error & 2.2, formal library launch #! / bin/bash echo starting java-jar admin-1.0-SNAPSHOT.jar-- spring.profiles.active=prod > log.file 2 > & 1 & 2.3, Stop the running project #! / bin/bash PID=$ (ps-ef | grep admin-1.0-SNAPSHOT.jar | grep-v grep | awk'{print $2}') if [- z "$PID"] then echo Application is already stoppedelse echo kill $PID kill $PIDfi2.4, restart the project #! / bin/bashecho stop applicationsource stop.shecho start applicationsource start.shJar package start and output the log in the background

Everyone deploys the project in the server, and the jar package needs to be started in the background, so it will not end the process because of your Ctrl+c, or if you close the terminal.

Format:

Nohup java-jar JarName > JarName.log &

Nohup... & # can make the process start in the background, and it is also suitable for many kinds of programs to start

When the jar package starts in the background, you need to put your startup command into it, or you can add other parameters when you start the jar package again.

For example, nohup java-Duser.timezone=GMT+8-Dfile.encoding=utf-8-Xms1024m-Xmx1024m-Djava.io.tmpdir=$DATA_DIR/tmp-jar $DATA_DIR "/" $JAR & these are all the contents of the article "how to start and configure log files using SpringBoot_jar". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Configuration file log background environment project method article process test content situation production not much preface parameters can make name command most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Xiaomi Docker Shulou Tech Info Linux