Documentation Center

Configuring logging of HTTP requests to microservices

In an application.properties or application.yml file for your microservice, ensure the presence of a number of properties in order to enable the logging of HTTP requests.

Procedure

  1. In the root folder of the microservice, create or open one of these two files:
    • application.properties, a traditional property-value file with a line of the format PROPERTY=VALUE on each line. Many properties listed below are already in the file in comments, so you can uncomment them.
    • application.yml, a YAML property-value file.
  2. If you use application.yml, add the following line anywhere in the file:
    server.tomcat.accesslog:

    and insert the settings that follow below it, indented.

  3. Enable access logging by adding the following line:
    In application.properties:
    Ensure the presence of the line:
    server.tomcat.accesslog.enabled=true
    In application.yml:
    Add the line:
       enabled: true
  4. Refer to the Apache Tomcat Access Log Valve reference at https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Log_Valve to create a pattern string that specifies what you log. For example, your pattern might be %h %l %u %t "%r" %s %b %D
  5. Set the pattern by adding the following line:
    In application.properties:
    Ensure the presence of the line:
    server.tomcat.accesslog.pattern=PATTERN

    where PATTERN is the pattern you created.

    In application.yml:
    Add the line:
       pattern: "PATTERN"

    where PATTERN is the pattern you created, using single quotes inside the pattern (for example, pattern: "%h %l %u %t '%r' %s %b %D").

  6. Set the directory in which to write the log files by adding the following line:
    In application.properties:
    Ensure the presence of the line:
    server.tomcat.accesslog.directory=DIRNAME
    In application.yml:
    Add the line:
       directory: DIRNAME

    where DIRNAME is the path to your log directory, for example, c:/UDP/.

  7. Set the suffix to append to the name of the log file by adding the following line:
    In application.properties:
    Ensure the presence of the line:
    server.tomcat.accesslog.suffix=SUFFIX
    In application.yml:
    Add the line:
       suffix: SUFFIX

    where SUFFIX is the ending of your log file name, for example, .log.

  8. Set a prefix to attach to the beginning of the name of the log file by adding the following line:
    In application.properties:
    Ensure the presence of the line:
    server.tomcat.accesslog.prefix=PREFIX
    In application.yml:
    Add the line:
       prefix: PREFIX

    where PREFIX is the beginning of your log file name, for example, access_log.

  9. Save and close application.properties or application.yml.
  10. Restart the microservice.