How to stop error_log() from prefixing my json logs with "NOTICE: PHP message:"

How to stop error_log() from prefixing my json logs with "NOTICE: PHP message:"
php
Ethan Jackson

Using php-fpm and nginx in a docker container. My custom php error handler builds a comprehensive JSON data and outputs it using error_log(). But somehow it is always prefixed with NOTICE: PHP message:, which ruins the JSON format reader in Grafana - because now the output is not a valid json string.

How do I stop it from prefixing my log strings?

Answer

You could just bypass the PHP logging by directly writting to a log file using file_put_contents

file_put_contents('/var/log/your.log', json_encode($data) . PHP_EOL, FILE_APPEND);

This avoids the NOTICE: PHP message: prefix and will produce a clean JSON to be uploaded to Grafana.

Related Articles