I have set the logging level in the spring boot application in application.yml
like this:
logging.level.com.Myapplicationname=DEBUG
The application is packaged and deployed as war on tomcat. Apart from this I haven't set the logback.xml
to define the log file etc.
Where can I see the console logs when some user uses the application over the browser?
Is there any default file created by framework?
By default, Spring Boot logs only to the console and does not write log files. If you want to write log files in addition to the console output, you need to set a logging. file or logging. path property (for example, in your application.
The default value is %SystemDrive%\inetpub\logs\LogFiles .
3.1. Spring Boot preconfigures it with patterns and ANSI colors to make the standard output more readable. As we can see, the default logging level of the Logger is preset to INFO, meaning that TRACE and DEBUG messages are not visible.
Spring Boot supports Log4j 2 for logging configuration if it is on the classpath. If you are using the starters for assembling dependencies that means you have to exclude Logback and then include log4j 2 instead. If you aren't using the starters then you need to provide jcl-over-slf4j (at least) in addition to Log4j 2.
You should either specify logging.file
or logging.path
, but not both ( when both are specified, logging.path
is ignored and only logging.file
is considered).
1. Using logging.file
You may use logging.file
one of the following way:
logging.file = logfile.log //in current folder logging.file = relativepath/to/logfile.log //relative path with filename logging.file = /fullpath/to/logfile.log //full path with filename
In Spring Boot Documentation:
By default, Spring Boot will only log to the console and will not write log files. If you want to write log files in addition to the console output you need to set a logging.file or logging.path property (for example in your application.properties).
In Spring Boot's how to logging doc:
If the only change you need to make to logging is to set the levels of various loggers then you can do that in application.properties using the "logging.level" prefix, e.g. You can also set the location of a file to log to (in addition to the console) using "logging.file".
2. Using logging.path
You could also use logging.path
to set the path, in which case the logfile will automatically be named spring.log
:
logging.path = ./ // -> spring.log in current folder logging.path = relativepath/to/logs // -> relativepath/to/logs/spring.log logging.path = /fullpath/to/logs // -> /fullpath/to/logs/spring.log
In Spring Boot doc:
[Using logging.path] Writes spring.log to the specified directory. Names can be an exact location or relative to the current directory.
springframework.guru on Spring Boot logging:
There is also a logging.path property to specify a path for a logging file. If you use it, Spring Boot creates a spring.log file in the specified path. However, you cannot specify both the logging.file and logging.path properties together. If done, Spring Boot will ignore both.
for those who are using spring boot 2.2.x you need to put this in configuration file
logging.file.name='/var/log/app.log'
or use this
logging.file.path='/var/log'
note that if you use logging.file.path it will writes spring.log to the specified directory. Names can be an exact location or relative to the current directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With