Search code examples
spring-cloudamazon-cloudwatchamazon-ecscloudcaptain

Best practice to handle logging via Cloud-Watch with Spring-Cloud-docker in ecs


I try for several days now to set up my docker-container with a spring-cloud app running to

  • log on an ec2-instance with "docker logs"
  • show my logging-entries in a logGroup at Cloud-Watch

My best result until now: I got in Cloud-Watch the upper 20 lines of the log (Spring-Brand in Ascii-Art and Spring version) and that's it. At that time the docker on EC2-instance showed the same with "docker logs", however the same docker on my system logged like usually. However, most of my attempts showed neither logging via "docker logs" nor via Cloud-Watch. But again, my app-logging via log4j2 by console-appender runs exactly like configured.

Even my local docker with the app.jar logs as expected (Windows7, Docker Toolbox, no Linux possible, unfortunately). Only on the EC2-instance there is silence with "docker logs".

Configuration:

  • Do I have the right docker image? openjdk:8-jdk-alpine
  • Are my Spring/AWS-Dependencies correct (we use mainly SQS): spring-cloud-aws-messaging, spring-cloud-aws-autoconfigure, spring-boot-starter-web, aws-java-sdk-sts
  • Do I need these logging-Dependencies, that I use now? spring-boot-starter-log4j2 (um alle Brücken für CommonsLogging zu haben)
  • Might the used logging in my app (log4j2 via slf4j) be the problem?
  • I tried the Console-Appender=>STDOUT=>awslogs way. And I tried (additionally or in exchange) cloud-watch-appenders(com.boxfuse.cloudwatchlogs:cloudwatchlogs-java-appender and pro.apphub:aws-cloudwatch-log4j2). With both appenders I fixed some initial configuration-errors and then I saw... nothing on Cloud-Watch.
  • In the ECS-Task I tried "awslogs"-Configuration to get Docker-STDOUT in Cloudwatch (that's what lead to the above mentioned first 20lines of logging). And I tried "json-file"-config to see something on EC2-instance with "docker logs". Both didn't lead to the whished result.

Can you perhaps give me a hint of something I might have missed?

Why only the first 20 lines of the log (Spring-Header?)

Why don't the appenders show the whished result? I hoped it would be as simple as "Graylog"... chose the right appender-config in log-config and voila, there are the log-entries.

Do you have some links for tutorials where logging from spring-cloud to Cloud-Watch is the topic with all necessary parts and steps explained?

Do you have some snippets (Pom, task-json, other hints), that might help me get this done?

Should it indeed be better to change for an "everything ready" solution like Boxfuse?

Thank you a lot!

PS: I know there are solutions with ELK-Stack and others, but I really would like to try Cloud-Watch first.


Solution

  • You can leave these fields of the task-definition, they said. The system will choose an appropriate default, they said. Don't bother, they said.

    Seems that I should have set a value for CPUs in the task-definition... The first couple of lines of log seem to be the only thing, that the 0-CPU-Task is able to produce... no other error message.

    I lough crying...