How can I set the logging path relative to tomcat dir /logs/mylog.log
?
What I tried: changing the logging.file
property in application.properties
leaving the filename out: #logging.file=
-> everything is logged to console, thus written into tomcat/logs/localhost.yyyy-mm-dd.log
logging.file=mylog.log
-> written to console, thus same as #logging.file
logging.file=d:/mylog.log
-> written to the location d:/mylog.log
logging.file=../logs/mylog.log
-> written to console, thus still to localhost*.log
None was successful. I'm not interested in externalising the configuration eg by providing system or environment variables.
The main Apache Tomcat configuration file is at /opt/bitnami/tomcat/conf/server. xml. Once Apache Tomcat starts, it will create several log files in the /opt/bitnami/tomcat/logs directory. The main log file is the catalina.
To make Spring Boot write its log to disk, set the path and filename. With this configuration, Spring Boot will write to the console and also to a log file called spring. log , at the path you specify.
The default logging configuration in Spring Boot is a Logback implementation at the info level for logging the output to console. The first info log is printed, followed by a seven-line banner of Spring and then the next info log. The debug statement is suppressed.
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.
I just created a simple Spring-boot
app from spring starter build as war
file. I have just this modification in @SpringBootApplication
class:
@SpringBootApplication
public class LogApplication {
private static final Logger logger = Logger.getLogger(LogApplication.class);
public static void main(String[] args) {
SpringApplication.run(LogApplication.class, args);
}
@Controller
@ResponseBody
public static class IndexController{
@RequestMapping("/")
public String getindex(){
logger.error("Error Logging");
return "Hello";
}
}
}
And this property in application.properties
:
logging.file=../logs/mylog.log
Build the application using maven mvn clean install
and put the war
file inside webapps
folder of tomcat
. Started tomcat using startup.bat
and hit successful the endpoint http://localhost:8080/demo-0.0.1-SNAPSHOT
.
And the log was written in logs/mylog.log
:
2017-01-04 14:57:10.755 ERROR 8236 --- [http-apr-8080-exec-4] com.example.LogApplication : Error Logging
You can make use of the environment variable for configuring the log path.
Tomcat sets a catalina.home system property which you can use
log4j.rootCategory=DEBUG,errorfile
log4j.appender.errorfile.File=${catalina.home}/logs/LogFilename.log
Note:-
This may not work On Debian (including Ubuntu), ${catalina.home} will not work because that points at /usr/share/tomcat6 which has no link to /var/log/tomcat6. Here just use ${catalina.base}. Check this link
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