Persisting logfiles with multiple containers

In a swarm, multiple containers will share the same volume, these containers write into a log file in the volume.
How am I supposed to split the logs? Or at least differentiate that log entry A was from container B?

You check whether setting a variable for the log file filename might work for you.

I tested out the available placeholders a while back:

If your containers don’t log to console or /dev/stdout and /dev/stderr, you need to make sure to take care of trimming the logs yourself to make sure they don’t grow infinitely. The docker way would be to print the logs to console or /dev/stdout and /dev/stderr, as it allows showing the logs with docker logs or docker service logs.