Reputation: 4613
We could set rotation for json-file logs of docker. If I set max-file=3
and max-size=10m
, there may be 2 rotated files and 1 connected file for a container. The question is, if I use docker logs
to view the logs of this container, can I see the logs in the 2 rotated files?
Upvotes: 5
Views: 1365
Reputation: 139
Seems like it, at least for the JSON driver.
You can test it yourself. Let's construct a case where the log files are split into two:
# docker run --log-driver json-file --log-opt max-size=1k --log-opt max-file=2 --name with_logs ubuntu /bin/bash -c 'echo test ; base64 /dev/urandom | head -c 1000'
# docker logs with_logs
Now your output looks something like this:
test
V9L4+Yud3l4+nyuz/J6PecuXNAcXRxiuWHv+6Lvpa34eDb/ktNTgGHxLLpFuJxmol+BCFoatZEX6
PKyqwOzot6PWnrjBwsA+CWpZUUpUMWh/ab1pF+5AYGU+n0nBudMMxehFVAzAP5PSVZdw0TvtZXGm
Trb5eHbMk1O35UF2fw7Mm8VsHEM5RPWUGO60aKODeRlPSkCogDHbGYtGVHtzyPYcL8wC64SEFTnv
(...)
As we can see, the test
output is still there, even though it should have spilled into the lograted file. Let's just verify that that is indeed the case. Notice that max-file
is set to 1:
# docker run --log-driver json-file --log-opt max-size=1k --log-opt max-file=1 --name without_logs ubuntu /bin/bash -c 'echo test; base64 /dev/urandom | head -c 1000'
# docker logs without_logs
yqdqW+91p2xHO58LTEzqnuwpeQncBshzm6KOutMjQh27m19D5XQ8ffIditEbgNfjc90UmxYHu1t1
arQ+3vYpzWzTSMxmxxOBTOKUKgAC36hVT3JcT+bYF2shLExdKsPA12OJFJj1gmCIF1BWhNVgsE3Z
(...)
As we can see, the echo test
is not visible anymore, as the logfile does not exist anymore.
To sum it up: Yes, rotated logs are visible in docker logs
Upvotes: 3