DEV Community

Cover image for How to see the error logs in WordPress with Docker in Linux
Carlos Guzmán
Carlos Guzmán

Posted on • Originally published at carlosguzman.dev on

How to see the error logs in WordPress with Docker in Linux

Recently I was working in the development of a WordPress plugin and I didn’t find an easy way to see the error logs in WordPress with Docker. I started to read and learn about Docker some few time ago. I created a WordPress development instance using the official Docker image for WordPress in Docker Hub. In some cases, you want to see the log of errors and do not activate the debug mode in WordPress. In example, a plugin can generate warnings that make difficult to debug and that could break responses for Ajax requests in your site.

My first attempt to see the error logs was to login in a bash session it the Docker container. Then I searched for the error log file but the errors are sent to the I/O stream STDERR by default.

Default configuration of error logs for WordPress with Docker
Default configuration of error logs for WordPress with Docker

Instead to create a custom image to change this configuration, I tried with the Docker cli tool to access to the logs of the container. Using docker logs ID_CONTAINER, I was able to see the logs of the web server. It was progress but it wasn’t what I want. I got all logs entries of the web server including access and warning entries. It would be difficult to spot the error entries easily in a website loading multiple resources and doing multiple Ajax requests.

Show logs of the Docker WordPress image container.
Show logs of the Docker WordPress image container.

The solution

If we discard the output sent to the standard stream, then the access entries are gone. So using docker logs -f ID_CONTAINER >/dev/null, we get only the entries sent to the error stream. Most of the entries here are the useful entries for debugging, they are the warning and error messages. The option -f in docker logs command is to follow and refresh automatically the logs in the console.

Show entries sent to the error stream only

Extra tip

If you want to see the error messages only without changing the error reporting directive, you can use the grep tool to filter the other entries. Using docker logs -f ID_CONTAINER 2>&1 >/dev/null | grep -i error, the entries are filtered to display only the lines with the error word in them. This command replaces the output of the standard stream with the output of the error stream. Then grep filters the content. The option -i in the grep command is to be case insensitive in the search.

Show only error logs of WordPress with Docker
Show only error logs of WordPress with Docker

Maybe it isn’t the most elegant but at least it is an effective way to see the error logs in WordPress with Docker.

The post How to see the error logs in WordPress with Docker in Linux appeared first on Carlos Guzman.

Top comments (0)