(I come from a Java development background, so please excuse my lack of PHP and WordPress knowledge.)
My understanding of logging in WordPress is that it must first be enabled in wp-config.php
and then calls to error_log()
can be seen and read.
But logging is not just about errors. It is very useful when developing and debugging to be able to log. For this reason many Java logging libraries (e.g. SLF4J) provide the ability to log at the following levels:
- TRACE (lowest)
- DEBUG
- INFO
- WARN
- ERROR (highest)
You can then configure the logging level that you wish to see in the log. For example when developing you would like to see DEBUG and above, but when running in production you probably just want to see WARN and above.
Is there something equivalent in WordPress? Logging everything as an error does not seem right.
(I come from a Java development background, so please excuse my lack of PHP and WordPress knowledge.)
My understanding of logging in WordPress is that it must first be enabled in wp-config.php
and then calls to error_log()
can be seen and read.
But logging is not just about errors. It is very useful when developing and debugging to be able to log. For this reason many Java logging libraries (e.g. SLF4J) provide the ability to log at the following levels:
- TRACE (lowest)
- DEBUG
- INFO
- WARN
- ERROR (highest)
You can then configure the logging level that you wish to see in the log. For example when developing you would like to see DEBUG and above, but when running in production you probably just want to see WARN and above.
Is there something equivalent in WordPress? Logging everything as an error does not seem right.
Share Improve this question asked Sep 29, 2020 at 15:26 vegemite4mevegemite4me 1353 bronze badges 1- 1 No, I don't think so, sorry. If you look in the included copy of PHPMailer that can use a PSR-3 LoggerInterface with different logging levels, but WordPress isn't set up for detailed tracing and logging no. – Rup Commented Sep 30, 2020 at 0:08
1 Answer
Reset to default 2Your understand is correct. WordPress doesn't have levels beyond Warning and Error from PHP.
Wonolog, a WordPress wrapper for Monolog, expands the default error logging into the levels you require. You can also expand the logging by adding your own custom debuging alerts and level.