Persisting logs to a central log storage location (Version 9.0.0.3 or later)
By persisting log files to a central location outside of the Docker containers, we can perform diagnostics and troubleshoot issues even if the container is not accessible or is destroyed. Starting with WebSphere Commerce Version 9.0.0.3, inside each Docker container, log files are collected to a unique folder name that is derived from the containerType and the containerId. For example, assuming that you have two Search server Docker containers, the log files are in the following directories.
- Search container 1: /opt/WebSphere/Liberty/usr/servers/default/logs/container/search_<containerId1>
- Search container 2: /opt/WebSphere/Liberty/usr/servers/default/logs/container/search_<containerId2>
Previously, log files were collected in the standard /logs/ directory, which made it hard to collect and organize files from different containers.
Note: To set the log folder to a different directory inside the container, we can use the following Run Engine command.
run set-trace-log-directory <new_log_path>For more information about how the start up process sets the log folder, see the /SETUP/bin/entrypoint.sh script. We can persist all container log files by creating a volume mount point to the Docker host machine or central log server. Since every container has its own unique log folder (containerType_containerId), we can simply mount all container log directories (*/logs/) to the same path on your host machine.
Task info
The following procedure provides an example for how to persist log files from a local WebSphere Commerce environment to the Docker host machine by using Docker Compose. We can also apply the same strategy to persist log files from environments deployed by using other tools such as Kubernetes or Marathon. For more information about mounting methods with other deployment strategies, refer to the respective official documentation.
Procedure
- Create a folder on the Docker host machine to store the log files.
For example, create a /logs directory to store files from the Transaction, Store, Search, xC, and Web servers.
The Utility server container does not follow the convention containerType_containerId since you do not need to deploy multiple Utility containers. Create a separate directory such as /logs/utils.
- Configure our Docker containers to start with a volume mount to the corresponding directory that you just created on the Docker host machine. For example, if we are using Docker Compose, edit the Compose file to add the volumes flag.
volumes: -"<log_folder_on_machine>":"<log_folder_in_container>"The following examples provide the paths to where the logs are generated in each container.
- For Transaction server Docker container,
volumes: -"/logs:/opt/WebSphere/AppServer/profiles/default/logs/container"
- For Web server Docker container,
volumes: - "/logs:/opt/WebSphere/HTTPServer/logs"
- For Search server Docker container,
volumes: -"/logs:/opt/WebSphere/Liberty/usr/servers/default/logs/container"The /opt/WebSphere/Liberty/usr/servers/default/logs/container directory also links to the /profile/logs directory in the container.
- For Store server Docker container,
volumes: -"/logs:/opt/WebSphere/Liberty/usr/servers/default/logs/container"The /opt/WebSphere/Liberty/usr/servers/default/logs/container directory also links to the /profile/logs directory in the container.
- For Customization server Docker container,
volumes: -"/logs:/opt/WebSphere/Liberty/usr/servers/default/logs/container"
- For Utility server Docker container
volumes: -"/logs/utils:/opt/WebSphere/CommerceServer90/logs" -"/logs/utils:/opt/WebSphere/CommerceServer90/instances/demo/logs"
See
- Deploy containers using the updated Docker Compose file.
Results
On your host machine, your /logs directory should have similar folders.
- /logs/search_<containerId>
- /logs/store_<containerId>
- /logs/ts_<containerId>
- /logs/web_<containerId>
- /logs/xc_<containerId>
- /logs/utils
What to do next
Think about how to handle log files from your production environment where we might have multiple containers of each component. For example, we might consider using multiple central log servers for load balancing. Or we can only persist the SystemOut.log file to the central log server in real time, and then configure a scheduler to asynchronously persist the trace.log file.