Prevent output of PHP errors/warnings in MODx.console?

I’m using a MODx.console window in my User Import plugin. So one can follow the import process live.
The problem is, that beside the wanted console output sometimes there are also PHP warnings and errors which can flood the console output.

Is it possible to prevent the output of messages other than the desired ones?

Desired messages should go to my MODx.console window and all others to MODX error log.

As far as I can tell, a request to your processor changes the default log target:

So to log different messages to different targets, you have to supply the third parameter when calling the log function:

Thanks @halftrainedharry,

this means, I can only control custom log messages. PHP errors/warnings and deprecation messages are always sent to the default stream.

When I set all my custom log messages to a custom log target, how do I tell the MODx.console window from where to fetch them?

This is the current output:
(the deprecation messages and warnings shouldn’t be there)

I have not tested this, but you can probably call setLogTarget again with the default target (that logs to the MODX error log) and then use the custom log target (the one that the console polls) for your own messages.

Deprecation notices tell you something is going to break in the future. As annoying as they may be, it’s best to track them down in either your own or the core code that is triggering them and make sure they get handled.

While you cannot reroute these messages because all logs are sent to the console, you can however change the error_reporting() level to stop PHP from emitting these deprecations (E_DEPRECATED). Make sure you get the issues logged somewhere first.

1 Like

Thanks Mark for your hint to change error_reporting() level! I’ll try this!

I simply don’t want these messages in a dedicated import status reporter as it makes the log unreadable for normal users (it’s not a developers log). This was the reason I asked if I could reroute the system-relevant messages to the MODX error log.

I’ll temporary change error_reporting level for only a few lines of code. The MODX log is still flooded with the same messages from other code parts in MODX - so nothing will get lost.