简体   繁体   English

在PHP和Wordpress中进行调试

[英]Debugging in PHP and Wordpress

@ini_set('log_errors','On'); and define('WP_DEBUG', true); define('WP_DEBUG', true);

I'm trying to create a error log file , but i'm confusing about these two. 我正在尝试创建一个错误日志文件,但我对这两个文件感到困惑。 what kind of errors will get by log_errors and WP_DEBUG ? log_errorsWP_DEBUG会得到什么样的错误?

The define('WP_DEBUG_LOG', true); define('WP_DEBUG_LOG', true); will log errors into the debug.log file in the wp-content directory, @ini_set('log_errors','On'); 将错误记录到wp-content目录中的debug.log文件中, @ini_set('log_errors','On'); allows you to specify the file where you want to save it. 允许您指定要保存的文件。 This should work for you: 这应该适合你:

@ini_set('log_errors', 1);
@ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */
@ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/your-error-file.log'); /* path to server-writable log file */
@ini_set( 'error_reporting', E_ALL ^ E_NOTICE ); /* the php parser to  all errors, excreportept notices.  */

The @ini_set('log_errors','On'); @ini_set('log_errors','On'); option sets the PHP handler to log errors. 选项设置PHP处理程序以记录错误。 It is a general configuration option used to control script's behaviour. 它是用于控制脚本行为的常规配置选项。 More on the function here 更多关于这里的功能

The define('WP_DEBUG', true); define('WP_DEBUG', true); on the other hand is very WP specific, it is used to capture and either print to screen / write to file WP specific errors. 另一方面非常特定于WP,它用于捕获并打印到屏幕/写入文件WP特定的错误。 More on it here . 更多关于它

Writing to a log file 写入日志文件

  1. PHP PHP

PHP stores error logs in /var/log/apache2 if PHP is an Apache2 module. 如果PHP是Apache2模块,PHP会将错误日志存储在/var/log/apache2 Shared hosts are often store log files in your root directory /log subfolder. 共享主机通常是在根目录/log子文件夹中存储日志文件。

If you have access to a php.ini file you can specify the path like this: 如果您有权访问php.ini文件,则可以指定如下路径:

error_log = /var/log/custom-logging-script.log
  1. WordPress WordPress的

You can tell WP to log entries to a file by setting define( 'WP_DEBUG_LOG', true ); 您可以通过设置define( 'WP_DEBUG_LOG', true );告诉WP将条目记录到文件中define( 'WP_DEBUG_LOG', true ); . That causes all errors to also be saved to a debug.log log file inside the /wp-content/ directory. 这会导致所有错误也被保存到/wp-content/目录中的debug.log日志文件中。

  1. Alternately 交替

If you quickly want to inspect a function or a variable then try something like this error_log($my_error, 3, "/var/tmp/my-errors.log"); 如果你想快速检查函数或变量,那么尝试类似于error_log($my_error, 3, "/var/tmp/my-errors.log"); . Its a handy function, more details here . 这是一个方便的功能, 更多细节

What you use depends on your requirement and what you want to debug. 您使用的内容取决于您的要求以及您要调试的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM