Persist logs to a central storage location

By persisting log files to a central location outside of the Docker containers, you can perform diagnostics and troubleshoot issues even if the container is not accessible or is destroyed.

Starting with HCL 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 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 difficult to collect and organize files from different containers.
Note: If you want to set the log folder to a different directory inside the container, use the following Run Engine command.
run set-trace-log-directory <new_log_path>
For more information about how the startup process sets the log folder, see the /SETUP/bin/entrypoint.sh script.
You can persist all container log files by creating a volume mount point to the Docker host machine or a central log server. Since every container has a unique log folder (containerType_containerId), mount all container log directories (*/logs/) to the same path on the host machine.
Image of the containers feeding to the central log storage

About this task

This procedure shows how to persist log files from a local HCL Commerce environment to the Docker host machine by using Docker Compose. Use 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

  1. 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 naming convention containerType_containerId. Create a separate directory with a name such as /logs/utils.

  2. Configure the Docker containers to start with a volume mount to the corresponding directory on the Docker host machine.
    If you 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 (xC) 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"
    For more information, see
  3. Deploy containers by using the updated Docker Compose file.

Results

Verify that the /logs directory on the host machine contains the following folders.
  • /logs/search_<containerId>
  • /logs/store_<containerId>
  • /logs/ts_<containerId>
  • /logs/web_<containerId>
  • /logs/xc_<containerId>
  • /logs/utils

What to do next

Determine how to handle log files from the production environment where multiple containers might exist for each component. For example, consider using multiple central log servers for load balancing. Alternatively, 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.