SeasLog 1.9.0 釋出, 支援修改預設變數及批量記錄陣列
SeasLog 1.8.6 釋出,包含多項功能改進,及Bug修復。
更新內容:
1.9.0
-
New Feature ofollow,noindex" target="_blank">#240 增加方法 SeasLog::setRequestVariable(key,value),可以支援使用者使用swoole等框架時改變SeasLog預設變數
-
New Feature #243 Log方法第一個引數支援陣列傳遞,如 SeasLog::debug(array).
-
Fixed issue #110 支援建構函式,可以使用 New SeasLog().
-
Fixed issue #245 為 analyzerCount 和 analyzerDetail新增單元測試例.
1.8.6
-
[重要]New Feature #218 新增SeasLog::closeLoggerStream(),解決CLI模式下檔案刪除後操作符釋放問題。
-
New Feature 新增資料收集建議文件.
-
New Feature 新增bench_mark.php批量測試指令碼
-
Fixed 解決check_log_level:log 中level級別匹配效能問題
-
Fixed 解決phpdbg下core dump問題.
-
Fixed 解決分析指令碼中smtp_secure和smtp_mailer問題.
-
Fixed issue #125 #203 新增配置項 seaslog.buffer_disabled_in_cli,預設為false.
-
Fixed issue #196 解決php5.3.x 下undefined symbol: expand_filepath_with_mode問題.
-
Fixed issue #195 修復rsyslog 使用 RFC5424 接收問題.
-
Fixed issue #200 當tcp/udp發生錯誤時提行提示.
-
Fixed issue #202 新增完整單元測試.
-
Fixed issue #210 新增配置項seaslog.remote_timeout, 預設為1秒.
-
Fixed issue #215 修復analyzerCount統計錯誤問題.
-
Fixed issue #228 修復analyzerDetail查詢錯誤問題.
1.8.4
-
New Feature #162 Configure seaslog.recall_depth support for filename and code line.
-
New Feature #170 Configure seaslog.trace_notice and seaslog.trace_warning support trace notice and warning.
-
New Feature #172 Configure seaslog.disting_folder support switch {Logger}/{Time}[.Type].log or {Logger}_{Time}[.Type].log.
-
New Feature #174 Add %U(MemoryUsage) and %u(PeakMemoryUsage) into default variable table.
-
New Feature #186 Use seaslog_throw_exception replace zend_error.
-
Fixed issue #65 Message template content match error.
-
Fixed issue #153 Disting_by_hour and disting_type can not use together.
-
Fixed issue #156 Log template format error with %L and %M.
-
Fixed issue #158 SeasLog::setRequestID intercepted error.
-
Fixed issue #165 Phpdbg seg fault.
-
Fixed issue #184 SeasLog::analyzerCount seg fault at PHP7-nts.
-
Fixed issue #181 Perfect when stream's connection was broken.
1.7.6
-
Fixed analyzerDetail bug, use grep -ai key_words.
-
Fixed issue #152. Segfault in cli.
1.7.5
-
License更新,從Apache License 2.0 更新到 PHP License 3.01.
-
遵循RFC5424規範傳送到 Rsyslog(TCP/UDP)
-
支援 RequestId 區分請求 fixed issue #134 .
-
更新 Analyzer 指令碼版本至 1.1.0, fixed issue #139 .
-
優化analyzerCount 和 analyzerDetail 統計函式效能,fixed issue #133 .
-
Fixed issue #138 . Error by file exists.
-
Fixed issue #140 . Error by setDatetimeFormat.
-
Fixed issue #142 . Error by too many open files.
-
Fixed issue #144 . Error by read log detail order desc.
-
Fixed issue #145 . Error by analyzerDetail.
-
Fixed issue #146 . Segfault at php-fpm.
附1:PECL專案主頁 http://pecl.php.net/package/SeasLog
附2:GitHub專案主頁 https://github.com/SeasX/SeasLog
附3: 碼雲專案主頁 https://gitee.com/neeke/SeasLog
SeasLog
Yet a log extension for PHP.A effective,fast,stable log extension for PHP
@author Chitao.Gao [ [email protected] ]
為什麼使用SeasLog
log日誌,通常是系統或軟體、應用的執行記錄。通過log的分析,可以方便使用者瞭解系統或軟體、應用的執行情況;如果你的應用log足夠豐富,也可以分析以往使用者的操作行為、型別喜好、地域分佈或其他更多資訊;如果一個應用的log同時也分了多個級別,那麼可以很輕易地分析得到該應用的健康狀況,及時發現問題並快速定位、解決問題,補救損失。
php內建error_log、syslog函式功能強大且效能極好,但由於各種缺陷(error_log無錯誤級別、無固定格式,syslog不分模組、與系統日誌混合),靈活度降低了很多,不能滿足應用需求。
好訊息是,有不少第三方的log類庫彌補了上述缺陷,如log4php、plog、Analog等(當然也有很多應用在專案中自己開發的log類)。其中以 log4php 最為著名,設計精良、格式完美、文件完善、功能強大。推薦。
不過log4php在效能方面表現非常差,下圖是SeasLog與log4php的ab併發效能測試( 測試環境:Ubuntu12.04單機,CPU I3,記憶體 16G,硬碟 SATA 7200):
那麼有沒有一種log類庫滿足以下需求呢:
-
分模組、分級別
-
配置簡單(最好是勿須配置)
-
日誌格式清晰易讀
-
應用簡單、效能很棒
SeasLog 正是應此需求而生。
目前提供了什麼
-
在PHP專案中便捷、規範地記錄log
-
可配置的預設log目錄與模組
-
指定log目錄與獲取當前配置
-
初步的分析預警框架
-
高效的日誌緩衝、便捷的緩衝debug
-
遵循 PSR-3 日誌介面規範
-
連線TCP埠,以RFC5424格式傳送日誌
-
連線UDP埠,以RFC5424格式傳送日誌
-
支援RequestId區分請求
-
支援日誌模板自定義
目標是怎樣的
-
便捷、規範的log記錄
-
高效的海量log分析
-
可配置、多途徑的log預警
SeasLog的效能究竟怎麼樣
當SeasLog不開啟buffer時,SeasLog是:
-
syslog()函式的8.6倍
-
file_put_contents()函式的240倍
-
fwrite()單例情況下的36倍
-
fwrite()非單例情況下的211倍
-
monolog不開啟buffer時的41倍
當SeasLog開啟buffer且buffer_size為100時,SeasLog是:
-
syslog()函式的250倍
-
file_put_contents()函式的6962倍
-
fwrite()單例情況下的1052倍
-
fwrite()非單例情況下的6127倍
-
monolog開啟buffer且buffer size為100時的118倍
bench_mark檔案位置: https://github.com/SeasX/SeasLog/blob/master/tests/bench_mark.php
預設變量表
SeasLog提供了下列預設變數,可以直接使用在日誌模板中,將在日誌最終生成時替換成對應值。
-
%L - Level 日誌級別。
-
%M - Message 日誌資訊。
-
%T - DateTime 如2017-08-16 19:15:02,受seaslog.default_datetime_format影響。
-
%t - Timestamp 如1502882102.862,精確到毫秒數。
-
%Q - RequestId 區分單次請求,如沒有呼叫SeasLog::setRequestId($string)方法,則在初始化請求時,採用內建的static char *get_uniqid()方法生成的惟一值。
-
%H - HostName 主機名。
-
%P - ProcessId 程序ID。
-
%D - Domain:Port 域名: 端 口號,如www.cloudwise.com:8080 ; Cli模式下為cli。
-
%R - Request URI 請求URI,如/app/user/signin; Cli模式下為入口檔案,如CliIndex.php。
-
%m - Request Method 請求型別,如GET; Cli模式下為執行命令,如/bin/bash。
-
%I - Client IP 來源客戶端IP; Cli模式下為local。取值優先順序為:HTTP_X_REAL_IP > HTTP_X_FORWARDED_FOR > REMOTE_ADDR
-
%F - FileName:LineNo 檔名:行號,如UserService.php:118。
-
%U - MemoryUsage 當前內容使用量,單位byte。呼叫zend_memory_usage。
-
%u - PeakMemoryUsage 當前內容使用峰值量,單位byte。呼叫zend_memory_peak_usage。
-
%C - TODO Class::Action 類名::方法名,如UserService::getUserInfo。