5

I am developing an app with Nodejs/Express and I am planning to run the app on AWS Fargate. For logging, I want to have the app logs available in AWS Cloudwatch. What is the best way to log Nodejs/Express to Cloudwatch? Is there a library which I can use?

MarcJ
  • 87
  • 1
  • 7

1 Answers1

5

There are many ways to collect logs, are you writing to the console, or using some logging tool. Here are some ideas:

If you are using Amazon ECS or Fargate with ECS then you can use the AWS Log driver.

If you are using Amazon EKS or Fargate with EKS then you can configure FluentD to log to cloudwatch.

CloudWatch Agent for Docker.

Use CloudWatch Container Insights to collect, aggregate, and summarize metrics and logs from your containerized applications and microservices. Container Insights is available for Amazon Elastic Container Service (Amazon ECS), Amazon Elastic Kubernetes Service (Amazon EKS), and Kubernetes platforms on Amazon EC2. Amazon ECS support includes support for Fargate.

In addition to logs, and insights you can log interactions between microservices using X-Ray. Here are some X-Ray examples with Fargate.

The EKS control plane can also be configured to log directly to CloudWatch.

As you mentioned you are using Node.Js, if you did not want to use console logging, but rather a library here are three:

Jason
  • 2,555
  • 2
  • 16
  • 17
  • Thank you. Logging to console is fine for me. What would be a good way to generate console logs in the application. Is Console.log() ans option or is some other way preferred? – MarcJ Jun 23 '20 at 19:34
  • Console.log is perfect, however, I think a standardised tool for looking such as Morgan, is a better alternative. Because you can change the logging output is required. – Jason Jun 24 '20 at 07:19