cedaro / satispress

Expose installed WordPress plugins and themes as Composer packages.
500 stars 49 forks source link

Only start logging when WP_DEBUG is true #86

Closed koenHuybrechts closed 5 years ago

koenHuybrechts commented 5 years ago

At this moment, Monolog is used to log certain (fatal?) errors in Satispress. But if one doesn't setup Monolog, the error fails and blocks Satispress from processing updates. Without any notification.

A solution cna be to implement an extra check if WP_DEBUG is enabled, so logging only happens when the website owner wants logging to happen.

marcus-hiles commented 5 years ago

👍 thanks for this

bradyvercher commented 5 years ago

SatisPress uses a null logger that implements the PSR-3 Logger interface so a custom logger that implements the same interface can be used. It doesn't actually write anywhere by default and it shouldn't swallow fatal errors -- those should still be handled by WordPress and respect the WP_DEBUG settings.

Monolog isn't actually used directly or even required if you want to log SatisPress messages. The logging docs demonstrate how to implement a logger using Monolog because it's widely used, makes for a concise example, and has a lot of handlers and formatters.

Some of the information SatisPress logs would probably just pollute debug.log since it's mostly useful for development, debugging, or monitoring, but replacing the NullLogger with a basic implementation that writes errors to debug.log when WP_DEBUG is enabled should be feasible.

bradyvercher commented 5 years ago

@koenHuybrechts Let me know if you have any feedback about the latest iteration on the logger. It should log warnings and higher when WP_DEBUG is enabled.