內容簡介
這個外掛程式與大部分外掛不同之處在於它使用了反向 hook。您可以在希望進行紀錄的位置加入 do_action,此外掛程式只會在啟用時將它們存到資料庫內。
日誌紀錄
這個外掛現在可以紀錄插件的活動 (已啟用、已停用、已刪除、已更新、已安裝),WordPress 更新時以及錯誤使用或時代已逝的函數被使用時的情況。
範例:
do_action( 'wp_log_info', '目前沒問題', '詳細紀錄的內容' );
if ( $something_bad_happened ) {
do_action( 'wp_log_error', '出問題啦!', '問題的詳細說明' );
...
}
您可以到後台中的「工具」>「日誌」查看、刪除和匯出日誌。只有擁有「manage_options」能力的使用者才能夠存取。
這個外掛會自動紀錄時代已逝的錯誤和未來即將淘汰的錯誤,而其餘就由您加入到程式碼中囉。
您可以紀錄決定特定活動或篩選器執行哪些函數。例如,若您想知道「init」鉤子執行的內容:
function check_init_hook() {
do_action( 'wp_log_debug_hook', 'init' );
}
add_filter( 'init', 'check_init_hook', 0 );
以下是您可以在程式碼中加入的不同層級的紀錄。您可以依自己的需求選擇使用任何層級,每個層級的說明只是指示。
緊急
系統無法使用
do_action( 'wp_log_emergency', $label, $message );
警示
必須立即採取行動。
do_action( 'wp_log_alert', $label, $message );
危急狀況
危急狀況。
do_action( 'wp_log_critical', $label, $message );
錯誤
不需要立即採取行動的執行階段錯誤,但通常應進行紀錄和監控。
do_action( 'wp_log_error', $label, $message );
警告
非錯誤的異常事件。
do_action( 'wp_log_warning', $label, $message );
注意事項
正常但重要的事件。
do_action( 'wp_log_notice', $label, $message );
資訊
有趣的事件。
do_action( 'wp_log_info', $label, $message );
除錯
詳細的除錯資訊。
do_action( 'wp_log_debug', $label, $message );
外掛標籤
開發者團隊
原文外掛簡介
This plugin uses hooks in the opposite way most plugins do. You add do_action where you want to do some logging and this plugin will save it to the database only when active.
Log Activity
This plugin now logs plugin activity (when activated, deactivated, deleted, updated, installed), when wordpress is updated, and when functions are used wrong or deprecated.
Example:
do_action( 'wp_log_info', 'So far ok', 'Details of what is ok.' );
if ( $something_bad_happened ) {
do_action( 'wp_log_error', 'This Happened!', 'Details of what happened.' );
...
}
See Tools->Logs to view, delete, and export the logs on the admin side. Only users with the manage_options capability will have access.
This plugin automatically logs deprecated and doing_it_wrong errors. The rest is what you add to your code.
You can log what functions will be run for a specific action or filter. For example if you want to see what runs in the ‘init’ hook:
function check_init_hook() {
do_action( 'wp_log_debug_hook', 'init' );
}
add_filter( 'init', 'check_init_hook', 0 );
The following are the different levels of logging to add to your code. You can use any level how you see fit, the descriptions of each level are just guidelines.
Emergency
System is unusable
do_action( ‘wp_log_emergency’, $label, $message );
Alert
Action must be taken immediately.
do_action( ‘wp_log_alert’, $label, $message );
Critical
Critical conditions.
do_action( ‘wp_log_critical’, $label, $message );
Error
Runtime errors that do not require immediate action but should typically be logged and monitored.
do_action( ‘wp_log_error’, $label, $message );
Warning
Exceptional occurrences that are not errors.
do_action( ‘wp_log_warning’, $label, $message );
Notice
Normal but significant events.
do_action( ‘wp_log_notice’, $label, $message );
Info
Interesting events.
do_action( ‘wp_log_info’, $label, $message );
Debug
Detailed debug information.
do_action( ‘wp_log_debug’, $label, $message );
