0

i'm trying to create a wordpress plugin that imports some products and i want to be able to log any errors that occur, in a text file. I know that error logging already exists using:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

but i want to make my own file logging only the errors that occur from my plugin. How can i do that?

1 Answers1

2

You can log errors directly to a .log file in your plugin directory as mentioned here: https://wordpress.stackexchange.com/questions/291108/how-to-log-plugin-errors-to-plugin-error-log-file

If you insist to write to a 'text file' then you can use this method: Write from WordPress plugin to text file with PHP

Make sure the folder you are writing the errors to has the correct permissions.

bbaskets
  • 84
  • 7
  • thk you, that was very helpfull... Also, in the first link you posted there is a comment that says that i can use `add_action('shutdown', 'custom_catch_fatals');` for fatal errors, but i amn't sure how can i pass the message of the fatal error inside the shutdown hook. maybe you know how can i do that? – Chris Tsironis Aug 24 '22 at 09:31