[WordPress] 外掛分享: WP Debug Logger

首頁外掛目錄 › WP Debug Logger
10+
安裝啟用
尚無評分
3386 天前
最後更新
問題解決
WordPress 2.9.2+ v0.1 上架:2011-07-25

內容簡介

這個外掛將支援的其他外掛的活動記錄到檔案中,讓您更容易找出問題所在。

如果有支援人員讓您安裝此外掛以解決問題,那麼安裝這個外掛就像安裝其他外掛一樣。安裝後,前往「設定」-> 「WP Logger」並啟用日誌紀錄。如果有多個支援的外掛,啟用您有興趣的那個外掛。

想使用這個外掛來為您自己的外掛添加日誌紀錄的開發人員應該參閱本文檔的「開發人員」部分。

本外掛的範本是 Mark Jaquith 的 Monitor Pages 外掛。非常感謝 Mark!

開發人員

其他外掛可以使用這個外掛來記錄重要事件,然後將這些事件傾倒到日誌檔案中。外掛需要將事件添加到全域陣列中,方式如下:

$GLOBALS[ 'wp_log' ][ '外掛名稱' ][] = '某些重要事件';

外掛還必須加入啟用的外掛清單。這樣,部落格所有者就可以在設定頁面上更輕鬆地過濾他們想要進行調試的外掛。添加和編輯以下代碼,以在外掛加載時執行。

$GLOBALS[ 'wp_log_plugins' ][] = '外掛名稱';

一個假想的例子可能是一個使用輸出緩衝區將字母 "a" 更改為 "A" 的外掛(讓我們稱之為 "Big A")。這個外掛記錄的事件可能包括以下內容:

$GLOBALS[ 'wp_log' ][ 'big_a' ][] = '建立輸出緩衝區';
$GLOBALS[ 'wp_log' ][ 'big_a' ][] = '輸出緩衝區回調';
$GLOBALS[ 'wp_log' ][ 'big_a' ][] = '在頁面中將 a 替換為 A';

此外掛接受 "wp_log" 陣列,然後將其傾印到上傳目錄中的檔案中。檔案在外掛設定頁面有連結,也可以在該頁面上刪除。這個檔案是一個簡單的文字檔案,並沒有任何保護措施,因此如果外掛記錄了 auth cookies,要小心一些。

如果您想為您的外掛添加一個 "log" 函式,請先檢查常數 WP_DEBUG_LOG 是否已定義,然後再添加到日誌類別中。如果您的外掛沒有使用類別,請確保您調用的日誌函式具有唯一名稱,以免與其他外掛衝突。

function log( $message ) {
if ( defined( 'WP_DEBUG_LOG' ) )
$GLOBALS[ 'wp_log' ][ '外掛名稱' ][] = $message;
}

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「WP Debug Logger」→ 直接安裝(推薦)

原文外掛簡介

This plugin logs the activity of supported plugins to a file, making it easier to figure out why there’s a problem.
If you have been asked to install this plugin because of a support issue then installing this plugin is just like installing any other plugin. Once installed, go to Settings->WP Logger and enable logging. If you have a number of supported plugins enable the one you are interested in.
Developers who want to use this plugin to add logging to their own plugin should see the Developers section of this documentation.
Mark Jaquith’s Monitor Pages plugin was used as a template for this plugin. Thanks Mark!
Developers
Other plugins can use this plugin to record important events which are then dumped to a log file. Plugins must add the event to a global array in the following way:
$GLOBALS[ 'wp_log' ][ 'name_of_plugin' ][] = 'Some important event';

Plugins must also add themselves to a list of enabled plugins. This will make it easier for blog owners to filter out which plugin they want to debug on the settings page. Add and edit the following code so it is executed when the plugin is loaded.
$GLOBALS[ 'wp_log_plugins' ][] = 'name_of_plugin';

A hypothetical example might be a plugin (let’s call it “Big A”) that uses the output buffer to change the letter “a” to “A”. The events recorded by this might include the following:
$GLOBALS[ 'wp_log' ][ 'big_a' ][] = 'Created output buffer';
$GLOBALS[ 'wp_log' ][ 'big_a' ][] = 'Output buffer callback';
$GLOBALS[ 'wp_log' ][ 'big_a' ][] = 'Replaced a with A in page';

This plugin takes the “wp_log” array and dumps it to a file in the upload directory of the blog it’s activated on. The file is linked from the plugin settings page and can be deleted on that page too. The file is a simple text file and is not protected in any way so be careful if auth cookies are logged by a plugin.
A “log” function isn’t included but if you want to add one to your plugin check the constant WP_DEBUG_LOG is defined before adding to the log array. If your plugin doesn’t use a class make sure that you call the log function a unique name so it doesn’t conflict with other plugins.
function log( $message ) {
if ( defined( 'WP_DEBUG_LOG' ) )
$GLOBALS[ 'wp_log' ][ 'name_of_plugin' ][] = $message;
}

延伸相關外掛

文章
Filter
Apply Filters
Mastodon