Skip to Content

Get Started with SAP Application Logging Service in the Neo Environment

test
0 %
Get Started with SAP Application Logging Service in the Neo Environment
Details

Get Started with SAP Application Logging Service in the Neo Environment

Requires Customer/Partner License
November 11, 2021
Created by
November 11, 2021
Configure logs and view them in the SAP BTP cockpit.

You will learn

  • How to configure log messages and loggers
QR code

Prerequisites


Step 1: Download the hello-world sample

See Install the SAP BTP SDK for Neo Environment.
For example, for Java Web Tomcat 8, download neo-java-web-sdk-<version>.zip.

Log on to answer question
Step 2: Configure logger message

Open the src\com\sap\cloud\sample\helloworld\HelloWorldServlet.java file in the hello-world sample and update the file with the following code:


package com.sap.cloud.sample.helloworld; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Servlet implementing simplest possible hello world application for SAP BTP Neo Environment. */ public class HelloWorldServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static final Logger LOGGER = LoggerFactory.getLogger(HelloWorldServlet.class); /** {@inheritDoc} */ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOGGER.info("Hello World!"); response.getWriter().println("<p>Hello World!</p>"); } }

Now you can view information about configured loggers when requesting the helloworld application. This information is also logged in the default trace logs with the text Hello World! when you set a log with level INFO.

Log on to answer question
Step 3: Download and install Apache Maven

See Welcome to Apache Maven.

Log on to answer question
Step 4: Install SAP JVM

See Install SAP JVM.

Log on to answer question
Step 5: Configure environment variables

Specify the JAVA HOME variable to the jre folder of the installed SAP JVM and the Path variable to the bin folder of the installed Apache Maven.

Log on to answer question
Step 6: Test and package the hello-world project

Go to the <installed SDK>/samples/hello-world folder in the command prompt and run the command mvn clean install to compile, test, and package the hello-world project.

You can now find your packaged WAR file in the target folder.

In the text area below, enter the command you used to compile, test, and package the hello-world project.

×
Step 7: Deploy the application

On the Java Applications page, deploy the WAR file and start the helloworld application. See Deploy on the Cloud with the Cockpit.

Deploy Application
Log on to answer question
Step 8: Open the application

Choose the helloworld application link to open the application’s Overview page and request the application by opening the application URL.

The application now displays the Hello World! message.

This operation guarantees that the logger is available.

Log on to answer question
Step 9: Configure Logger
  1. Go to the Logging page.

  2. Set the log level.

    Set the INFO log level of the com.sap.cloud.sample.helloworld.HelloWorldServlet logger that you added to HelloWorldServlet.java. See the Configure Loggers section in Using Logs in the Cockpit for Java Applications.
    Furthermore, you can find information about the various log levels at Implementing Logging for Java Applications.

    Set INFO log level

In the text area below, enter the logger that you set the log level for.

×
Step 10: Request the application

Go to the Overview page and choose the application URL.

The application now displays the Hello World! message.

Log on to answer question
Step 11: View the logs
  1. Go back to the Logging page, display the HTTP access log in a log viewer and search for the path hello-world to see the helloworld application logs. For more information, see Log Viewers for Java Applications. HTTP access logs

  2. From the Logging page, display the default trace in a log viewer and search for text Hello World! to find the logs from the request operation. Default trace logs

Log on to answer question

Next Steps

Back to top