Logging in SAP Cloud Platform CloudFoundry Environment
It’s a good approach for ABAPers to learn new technology like Open-Source tool by comparing them with the good-old stuff in Netweaver available many years ago.
The aim of this blog is to give you a brief introduction how to do logging in your application code and view those logs via Kibana. Before start, let’s recall how the same requirement is done in ABAP.
Logging in Netweaver
There are several logging mechanisms available in Netweaver, for example application log or checkpoint supported by ABAP language itself.
Since this blog is not a cookbook for ABAP logging, I will not list detailed step but only give some higlight. In order to do logging in your application code, you need to use a standard or create your own checkpoint group via tcode SAAB. I personally treat this checkpoint group as the application log instance to be created in SAP Cloud Platform soon.
Here I use the standard checkpoint group DEMO_CHECKPOINT_GROUP.
Press “Display <->Activate” to enter edit mode, set Logpoints as “Log”, date field as “Today”, meaning the log only takes effect within today.

Create a configuration for user on whom the log must be switched on.

Create a report with name ZCONTEXT, and log the value of system variable sy-cprog and reporting running mode(online or offline, stored in sy-batch) into the standard checkpoint group.

Execute the report and go back to tcode SAAB to see the expected log record.

CloudFoundry environment in SAP Cloud Platform
The official guideline is documented in SAP Github.
It is recommended to use slf4j(Simple Log Facade for Java). As it name hints, slf4j works as an interface to provide log functionality; the concrete logging implementation could be decided by developers based on project requirement.
I have built a simple example and upload it to my github to demonstrate how to use logging. In my example I use log4j2 as slf4j implementation.
1. define version of slf4j and log4j2 in pom.xml of Java project.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<cf-logging-version>2.1.5</cf-logging-version>
<log4j2.version>2.8.2</log4j2.version>
<slf4j.version>1.7.24</slf4j.version>
</properties>
Maintain dependency for slf4j and log4j2 in pom.xml as well:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.sap.hcp.cf.logging</groupId>
<artifactId>cf-java-logging-support-log4j2</artifactId>
<version>${cf-logging-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>com.sap.hcp.cf.logging</groupId>
<artifactId>cf-java-logging-support-servlet</artifactId>
<version>${cf-logging-version}</version>
</dependency>
2. Create log4j2.xml file in CLASSPATH folder( resources folder in my case):
<Configuration status="warn" strict="true"
packages="com.sap.hcp.cf.log4j2.converter,com.sap.hcp.cf.log4j2.layout">
<Appenders>
<Console name="STDOUT-JSON" target="SYSTEM_OUT" follow="true">
<JsonPatternLayout charset="utf-8" />
</Console>
<Console name="STDOUT" target="SYSTEM_OUT" follow="true">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} [%mdc] - %msg%n" />
</Console>
</Appenders>
<Loggers>
<!-- Jerry: Log level: INFO -->
<Root level="${LOG_ROOT_LEVEL:-INFO}">
<AppenderRef ref="STDOUT-JSON" />
</Root>
<Logger name="com.sap.hcp.cf" level="${LOG_HCP_CF_LEVEL:-INFO}" />
</Loggers>
</Configuration>
3. Create a new log instance ( do you still remember the checkpoint group in ABAP? ) in SCP Cockpit:

I name it as “jerry-log”:

4. use slf4j API for logging:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectivityServlet.class);
In my example, I log the connection detail for ABAP On-Premise system in my code:

5. Log monitoring
Click Logs tab in Cockpit, press button “Open Kibanna Dashboard”, and the corresponding log record for the connection detail mentioned in step 4 is visible there.

The log instance “jerry-log” created in step 3 is also listed in the log detail message.

Right now, if you are opening the Kibanna Dashboard, you are able to see all applications logs. So everybody can see everything. Is it possible to implement some kind of authorizations conecpt, so the views are restricted for certain users?
Usecase: External agency want to only see the logs of their implemented application. Other applications are of no interest for them.