Comment mettre les logs dans wordpress
2 réponses
- votes
-
- 2017-03-16
Vouspouvez activer lajournalisation WordPressen ajoutant ceci à
wp-config.php
:// Enable WP_DEBUG mode define( 'WP_DEBUG', true ); // Enable Debug logging to the /wp-content/debug.log file define( 'WP_DEBUG_LOG', true );
vouspouvez écrire dans lefichierjournalen utilisant lafonction
error_log()
,c'est un wrapper defonctiontrès utilepour cela,rendez-le disponible dans votreplugin:if (!function_exists('write_log')) { function write_log($log) { if (true === WP_DEBUG) { if (is_array($log) || is_object($log)) { error_log(print_r($log, true)); } else { error_log($log); } } } } write_log('THIS IS THE START OF MY CUSTOM DEBUG'); //i can log data like objects write_log($whatever_you_want_to_log);
si vousne trouvezpas lefichier
debug.log
,essayez degénérer quelque chosepour lui,carilne serapas créé s'iln'y apas d'erreurserrors
,également sur certains serveurs hébergés vous devrezpeut-être vérifier où setrouve lejournal deserreurs à l'aide desinformationsphp.You can enable WordPress logging adding this to
wp-config.php
:// Enable WP_DEBUG mode define( 'WP_DEBUG', true ); // Enable Debug logging to the /wp-content/debug.log file define( 'WP_DEBUG_LOG', true );
you can write to the log file using the
error_log()
function, this is a very useful function wrapper for it, make it available in your plugin:if (!function_exists('write_log')) { function write_log($log) { if (true === WP_DEBUG) { if (is_array($log) || is_object($log)) { error_log(print_r($log, true)); } else { error_log($log); } } } } write_log('THIS IS THE START OF MY CUSTOM DEBUG'); //i can log data like objects write_log($whatever_you_want_to_log);
if you cant find the
debug.log
file, try generating something for it, since it will not be created if there are noerrors
, also in some hosted servers you might need to check where the error log is located using php info.-
Pour une utilisationfacile de lafonction write_log,je l'ai crééeen tant queplugin https://github.com/manchumahara/cbxwpwritelog si cela aide.Je l'utilisetous lesjours à desfins de développement.For easy use of the write_log function I have created it as plugin https://github.com/manchumahara/cbxwpwritelog if that helps. I am using it everyday for development purpose.
- 0
- 2018-12-17
- Manchumahara
-
- 2017-03-16
WordPresspeutfaire de lajournalisation! Consultez lapage de débogage WordPressici https://codex.wordpress.org/Debugging_in_WordPress
J'aimegénéralement configurermes sites Web de développement locauxpour qu'ils consignent leserreurs dans unfichier de débogage,plutôt que de les afficher à l'écran.
Accédez à votrefichier wp_configet faites défiler vers lebas oùil définit WP_DEBUG.
Voici à quoi ressemblema configurationtypique:
define('WP_DEBUG', true); // To enable debugging. Leave things just like this to output errors, warnings, notices to the screen: define( 'WP_DEBUG_LOG', true ); // To turn on logging define( 'WP_DEBUG_DISPLAY', false ); // To prevent output of errors, warnings, notices to the screen (which I personally find SUPER annoying):
Avec cesparamètres,WordPressenregistrera désormais leserreurs,les avertissementset lesnotifications dans unfichier
debug.log
situé dans/wp-content/debug.log
Lesfichiersjournaux dans lesenvironnements deproduction constituent desmenacespour la sécurité. SI vous décidez de vous connecter à unenvironnement deproduction,il seraitjudicieux de définir votrefichier .htaccesspour refuser l'accès aufichierjournal ( ou utiliser de lamêmemanière unplugin de sécuritépour lebloquer). De cettefaçon,vous obteneztoujours vosjournaux,mais vousn'avezpas à vous soucier despiratesinformatiques qui obtiennent égalementtoutes cesinformations.
WordPress can do logging! Check out the WordPress debugging page here https://codex.wordpress.org/Debugging_in_WordPress
I typically like to set my local development websites up to log errors in a debug file, rather than to have them output on the screen.
Head over to to your wp_config file and scroll to the bottom where it defines WP_DEBUG.
This is what my typical setup looks like:
define('WP_DEBUG', true); // To enable debugging. Leave things just like this to output errors, warnings, notices to the screen: define( 'WP_DEBUG_LOG', true ); // To turn on logging define( 'WP_DEBUG_DISPLAY', false ); // To prevent output of errors, warnings, notices to the screen (which I personally find SUPER annoying):
With those settings, WordPress will now log errors, warnings, and notices to a
debug.log
file located in/wp-content/debug.log
Log files in production environments are security threats so IF you decide to have logging on a production environment, it would be a good idea to set your .htaccess file to deny access to the log file (or similarly use a security plugin to block it). That way you still get your logs, but don't have to worry about hackers getting all that info as well.
-
Puis-je y ajouter dutextepersonnalisé?Parexemple dans uneboucle Justepour obtenir la confirmation de quiest appelé,je veuxentrer desnombres comme 1,2,3etc. Commentpuis-je lefaireCan I add any custom text in it? For example in a loop Just to get confirm which is called I want to enter numbers like 1,2,3 etc. How can I do it
- 0
- 2017-03-16
- Pratik bhatt
-
Vouspouvez.Vérifiez la réponse de @ davidpour savoir commentfaire cela :) Voici unbon article à ce sujet https://www.elegantthemes.com/blog/tips-tricks/using-the-wordpress-debug-logYou can. Check @david's answer for how to do that :) Here's a good article on that https://www.elegantthemes.com/blog/tips-tricks/using-the-wordpress-debug-log
- 2
- 2017-03-17
- Ian
Est-ilpossible queje puisseenregistrer quoi que ce soit dans wordpress similaire auxjournaux quenouspouvonsfaire dans Magento.
J'intègre unpluginpersonnalisé dans lequelj'ai ajouté quelquesfonctions à l'aide de hooks,doncj'aibesoin de déboguer quelque chose dedans.En cela,j'aibesoin de savoir sije peuxentrer dutexte ou des données dans lesjournaux wordpress.
Si c'est le cas,merci deme fairepart de laprocédure de création de connexion dans wordpress.