最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does Wordpress provide different levels of logging?

programmeradmin6浏览0评论

(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
Add a comment  | 

1 Answer 1

Reset to default 2

Your 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.

发布评论

评论列表(0)

  1. 暂无评论