## 4.1.3.5.1.9.1  Configure a Java Application for Logs and Traces
Configure the collection of log and trace messages generated by a Java application in SAP BTP, Cloud Foundry.
## Prerequisites
- You have bound an application to the SAP Application Logging service. See: Logging and Tracing [page 324]
- You have installed and configured Maven.
- For SAP Java Buildpack 1 : Y ou use SAP JVM 8 or SapMachine 11 or 17, and your &lt;JAVA\_HOME&gt; environment variable points to this location.
- For SAP Java Buildpack 2 : Y ou use SapMachine 17 or 21, and your &lt;JAVA\_HOME&gt; environment variable points to this location.
- You do not have any SLF4J and logback JAR files in the application.
##  Caution
The JARs for the SLF4J and logback are included as part of the Tomcat and TomEE runtimes provided by SAP Java Buildpack. Packing them in the application can cause problems during class loading.
## Context
The recommended framework for logging is Simple Logging Facade for Java (SLF4J). To use this framework, you can create an instance of the org.slf4j.Logger and org.slf4j.LoggerFactory classes. You can use SLF4J to configure your Java application to generate logs and traces, and if appropriate - set the logging and tracing levels.
##  Note
It is the application's responsibility to ensure that the logback is configured in a secure way in the case when the application overrides the default logback configuration included in SAP Java Buildpack. See step 2 below.
## Procedure
1. Instruct Maven that the application should not package the SLF4J dependency, since it's already provided by the runtime.
To do that, go to the pom.xml file and set scope provided for the following dependency:
- For SAP Java Buildpack 1:
&lt;dependency&gt;
```
<groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.36</version> <scope>provided</scope> </dependency>
```
- For SAP Java Buildpack 2:
2. (Optional) Configure the logback in case the application overrides the default logback configuration. To do that, you need to perform the following steps:
1. Under path META-INF/sap\_java\_buildpack/resources/tomcat/conf , create a custom logback.xml file. For example:
2. Create a resource\_configuration.yml file or add the following entries to your existing resource\_configuration.yml file (if using T omcat):
```
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>2.0.13</version> <scope>provided</scope> </dependency>
```
```
 Example <?xml version="1.0" encoding="UTF-8"?> <configuration debug="false" scan="false"> <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="${encoder}"> ${pattern} </encoder> </appender> <root level="INFO"> <appender-ref ref="STDOUT"/> </root> </configuration>
```
```
 Example ---tomcat/conf/logback.xml: pattern: '' encoder: ''
```
NOTE: Y ou can also add default values for pattern and encoder .
3. Add the following property in your manifest.yml file. For example (if using T omcat):
```
 Example ---applications: - name: <APP_NAME> ... env: JBP_CONFIG_RESOURCE_CONFIGURATION: "['tomcat/conf/logback.xml': {'encoder': 'com.sap.hcp.cf.logback.encoder.JsonEncoder', 'pattern': ''}]"
```
## Related Information
Configure the Access Logs of an Application [page 329]