[WordPress] 外掛分享: WP MyLogger

首頁外掛目錄 › WP MyLogger
WordPress 外掛 WP MyLogger 的封面圖片
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
10+
安裝啟用
尚無評分
4021 天前
最後更新
問題解決
WordPress 3.5.1+ v0.0 上架:2015-03-12

內容簡介

若要使用自定義的附加器,請在你的初始外掛中加入以下程式碼(以LoggerAppenderDailyFile、LoggerAppenderRollingFile、LoggerAppenderFile、LoggerAppenderMail、LoggerAppenderMailEvent等附加器為選項),對於每一種類型,你必須具體指定相關的參數,參考log4php的官方文件。

針對滾動檔案附加器:

$parameters = array(
'fileName' => __DIR__.'/logs/debug.log',
'fileAppend' => true,
'maxSize' => '1MB',
My_Logger::ROLLING_APPENDER => true,
My_Logger::ROLLING_MAX_BACKUP_INDEX => 5
);
$mylogger = My_Logger::get_instance('', My_Logger::ROLLING, $parameters);
$this->logger = $mylogger->getLogger();
// 增加測試輸出:
$this->logger->debug($parameters);
$this->logger->debug('test');

針對郵件附加器:

$parameters = array(
'smtpHost' => '',
'smtpUsername' => '',
'smtpPassword' => '',
'from' => '',
My_Logger::MAIL_TO => '',
My_Logger::MAIL_SUBJECT => '',
My_Logger::THRESHOLD => My_Logger::LEVEL_DEBUG
);
$mylogger = My_Logger::get_instance('', My_Logger::MAIL, $parameters);

** 設定Logger的閥值 ** 閥值用來描述輸出訊息的嚴重性,共有六個級別,按降序排序如下。你可以透過加入下列參數來設定Logger的閥值:

FATAL:最嚴重的錯誤事件,應用程式會因此中止。
ERROR:尚可容忍的錯誤事件,應用程式可以繼續執行。
WARN:可疑事件,應用程式可以繼續執行。
INFO:粗略的應用程式進展訊息。
DEBUG:適用於除錯的詳細應用程式進展事件。
TRACE:最詳細的應用程式進展訊息。

若想要在前端放置Logger,請在模板Script中加入以下程式碼:

$parameters = array(
'fileName' => __DIR__.'/logs/debug.log',
'fileAppend' => true,
'maxSize' => '1MB',
My_Logger::ROLLING_APPENDER => true,
My_Logger::ROLLING_MAX_BACKUP_INDEX => 5,
My_Logger::THRESHOLD => My_Logger::LEVEL_DEBUG
);
$mylogger = new My_Logger('', My_Logger::ROLLING, $parameters);
$logger = $mylogger->getLogger();
$logger->debug('test my logger');

詳細資訊可參閱log4php的API文件:Apache Log4php Docs

** 設定 ** 你可以在外掛的設定中設定其配置檔案的路徑,以導出Logger

外掛標籤

開發者團隊

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

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

原文外掛簡介

To use the custom appenders, add this code in your init plugin for example: Choose among appenders (LoggerAppenderDailyFile, LoggerAppenderRollingFile, LoggerAppenderFile, LoggerAppenderMail, LoggerAppenderMailEvent), for each type you must
specify the relative parameters, how to official documentation of log4php.

For rolling file appenders:
‘1MB’, My_Logger::ROLLING_APPENDER => true, My_Logger::ROLLING_MAX_BACKUP_INDEX => 5 ); $mylogger = My_Logger::get_instance(“”, My_Logger::ROLLING, $parameters); $this->logger = $mylogger->getLogger(); //for debug you add: $this->logger->debug($parameters); $this->logger->debug(“test”); ?>

For mail appender: ”, My_Logger::MAIL_TO => ”, My_Logger::MAIL_SUBJECT => ”, My_Logger::THRESHOLD => My_Logger::LEVEL_DEBUG//6: Sets the root logger level to DEBUG. This means that logging requests with the level lower than DEBUG will not be logged by the root logger. );
$mylogger = My_Logger::get_instance(“”, My_Logger::MAIL, $parameters); ?>

** SET Logger threshold ** A level describes the severity of a logging message. There are six levels, show here in descending order of severity. You can set level of logger, add the parameter:

FATAL Highest Very severe error events that will presumably lead the application to abort.
ERROR … Error events that might still allow the application to continue running.
WARN … Potentially harmful situations which still allow the application to continue running.
INFO … Informational messages that highlight the progress of the application at coarse-grained level.
DEBUG … Fine-grained informational events that are most useful to debug an application.
TRACE Lowest Finest-grained informational events.

If do you want put a logger in frontend, add this code in template script: ‘1MB’, My_Logger::ROLLING_APPENDER => true, My_Logger::ROLLING_MAX_BACKUP_INDEX => 5, My_Logger::THRESHOLD => My_Logger::LEVEL_DEBUG );
$mylogger = new My_Logger(“”, My_Logger::ROLLING, $parameters);
$logger = $mylogger->getLogger(); $logger->debug(“test my logger”); ?>
For more info read the API documents of log4php:Apache Log4php Docs
** Configuration ** You can set configuration path file to export your logger, in the plugin’s settings.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon