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
- 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=VALUEon 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.
- application.properties, a traditional property-value file with a line of the format
- 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.
- 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
- 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 - Set the pattern by adding the following line:
- In application.properties:
-
Ensure the presence of the line:
server.tomcat.accesslog.pattern=PATTERNwhere 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").
- 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/.
- 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.
- 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.
- Save and close application.properties or application.yml.
- Restart the microservice.