4

As a newbie to Docker: I am using a Docker host to run around 11 containers, and one of the containers is running java application, in which I used log4j logging to log. How can I access only the logs while running the Docker compose. I have tried to capture the logs to a log4j.log file, but this only creates after the termination of the java application.

Jayan
  • 17,353
  • 13
  • 86
  • 137
Balu
  • 147
  • 2
  • 10
  • It may more useful to setup a network logging. You send the logs outside the container (say to a central location) and analyse it. See http://stackoverflow.com/questions/11759196/log4j-how-to-use-socketappender – Jayan Apr 24 '15 at 07:13

1 Answers1

3

Assuming that you have configured log4j to log into std out and you are running application by using commnad: java -jar ... you should be able to check logs using:

$ docker-compose logs name_of_container
Alejandro Galera
  • 3,104
  • 3
  • 21
  • 38
wsl
  • 7,491
  • 1
  • 19
  • 23
  • It works!, thanks for the tip, One small issue is that, with one server I have used supervisor to spawn two processes, one for execution of java with ant script and other for starting tomcat7. In this case am not able to see the logs. – Balu Apr 26 '15 at 14:37
  • Generally it is not a good idea to have supervisor or run more than one application inside single container. It can cause you a problem for example if one of the applications will stop working. – wsl Apr 27 '15 at 07:06
  • Yes I did observe that. Will try not to. Thanks! – Balu Apr 28 '15 at 08:29