How can I persist logging beyond application running scope?

System Information
  • Strapi Version: 3.4.0
  • Operating System: Linux (node:12 docker)
  • Database: MySQL
  • Node Version: 12.22.3
  • NPM Version:
  • Yarn Version: 1.22.10

Hello,

I’m using Strapi for the first time and I’ve inherited a strapi application running within Azure Container Instances and I am having a some issues with the container restarting ~every hour.

It seems to be an application error, and I suspect a cron job we have running, the issue though is I cannot see any logs.

Given the strapi logs are output to console, usually I would see them within the Azure Portal UI or by running azure container logs command. For both my ngnix image and the client (Next) this is the case.

However when tryng to view strapi logs I get this message:

←[91mFail to decode container log with utf-8 encoding. please write log in utf-8←[0m

To get visibility of the logs I either need to:

  1. Log to a file instead of console, how is this possible with strapi?

  2. Fix logs encoding, again now sure how to do this within strapi?

Any pointers in the right direction would be greatly appreciated.

Thank you!

Since you are already using Azure services, why don’t you use Application Insights for monitoring?

Or Sentry? Introducing the new official Sentry plugin for Strapi

Thank you for your suggestions. Not sure I hadn’t thought about App Insights. :man_facepalming:

Actually looks like Azure Monitor - Log Analytics workspaces are a better fit for the Azure Container Instances so I’m going with that.

I did also try adding Sentry, which works for my Next.js frontend, but I think I’ve hit this open issue (GraphQL plug-in prevents Sentry middleware from catching errors · Issue #10354 · strapi/strapi · GitHub) with Strapi trying to log to Sentry.

I suspect the log analytics will be enough though as I will get persisted console logs.

Thank again.

If you just need to write logs in to a file, then you can use pm2 for that. You can run the strapi app with it, and modify the configs to write logs to the files that you desire. Also it has a nice feature that it writes normal logs and errors in separate files.

Yup I second this, instead of running Strapi in the container directly with node you can use PM2 instead which has various configuration options to either dump to a file or convert the output into JSON (useful when using other services like Graylog for centralized log management).

I even wrote a Graylog PM2 module a while back now: