I am using Spring boot to build a simple REST service and I am wondering about the most appropriate way to handle the logging.
In my application.properties file I have the following:
logging.level.org.springframework.web: DEBUG
While developing the application I simply run it as such:
java -jar myapp.war
thus, I got all the nice log messages in stdout. However, I intend to deploy it, and I'm wondering what is the most appropriate way to deploy the application and still have my logs.
Sure, one can simply redirect the output
java -jar myapp.war >> somefile
but this is not very elegant, and I want to deploy my application so that it can easily be used as a service:
ln -s /my/app/xyz.war /etc/init.d/xyz
Then, doing
service xyz start|stop|restrart
to manage it. Seems like doing this prevents me from redirecting stdout ..
Any ideas or advice about this?
What you are really after is Spring Boot file logging output functionality.
Quoting the above documentation:
Essentially adding in your
application.properties
:In you application.properties file you can set two attributes for your logging.file.
Like in the documentation description: (26.3 File output)
logging.file
logging.path
After setting one of those logging properties will be written in a file.
Here you can find the complete doc
Why wouldn't you wrap it in docker container?
It will give you possibility to have everything inside the container and distribute it easily.
Spring Boot support almost every logging frameworks you can use as per your convenience, but I will suggest you to use slf4j logging framework and customize using logback.xml it's very easy look at
1) Create LOGGER object adding this single line of code in your class
2) Create logback.xml file in /resource folder and copy below code
Using logback.xml configuration you can customize your application logging in spring boot