如何從我的WP插件編寫調試消息?Wordpress調試
http://codex.wordpress.org/Debugging_in_WordPress描述如何啓用wp-content/debug.log
文件。但我怎麼寫信給它呢?有沒有像wp_log($msg)
之類的日誌記錄方法?我沒有找到這樣的。
如何從我的WP插件編寫調試消息?Wordpress調試
http://codex.wordpress.org/Debugging_in_WordPress描述如何啓用wp-content/debug.log
文件。但我怎麼寫信給它呢?有沒有像wp_log($msg)
之類的日誌記錄方法?我沒有找到這樣的。
如果WP_DEBUG_LOG
設置爲true,則error_log
-INI setting設置:
ini_set('error_log', WP_CONTENT_DIR . '/debug.log');
寫入該文件,你可以使用error_log
-function:
error_log("This message is written to the log file");
此功能是不特定於WordPress和可以用在任何PHP腳本中。
下面是一個簡單的函數,你可以使用;如果啓用WP_DEBUG只會記錄消息:
function log_me($message) {
if (WP_DEBUG === true) {
if (is_array($message) || is_object($message)) {
error_log(print_r($message, true));
} else {
error_log($message);
}
}
}
可以調用log_me()
功能像這樣在你的主題模板(S):
log_me('This is a message for debugging purposes');
將在您的/wp-content/debug.log
顯示如下行:
[13-Apr-2013 20:59:17 UTC] This is a message for debugging purposes
謝謝,它的工作。 – 2013-02-26 09:45:05