歡迎您光臨本站 註冊首頁

PHP日誌擴展 SeasLog-1.4.4 發布, 重要 bug 修復

←手機掃碼閱讀     admin @ 2015-09-25 , reply:0

SeasLog-1.4.4 發布!

重要bug修復:  trace_error與trace_exception出現循環hook.

請使用者儘快升級至1.4.4版.

SeasLog是一個輕量,高效,便捷,規範的PHP日誌擴展,精準的定位\精巧的設計,使它在PHP項目中逐步成為一個非常優秀的日誌工具.

Change log:

1.4.4

- Fixed issue #50 Fix error and exception hook dead loop.
- Fixed support windows with new version.
- Fixed trace_error default enable and trace_exception default disable.

1.4.2

- Fixed issue #47 support trace_error and trace_exception switch.
- Fixed issue #48 Ignore notice or warning, but error automatic logging.

1.4.0

- Fixed issue #42 support error and exception automatic logging.
- Optimization performance, update is_dir with access.

1.2.3

- Fixed issue #44 Seaslog::analyzerDetail([with out 'all'])
- Support CONST SEASLOG_ALL

1.2.2

- Fixed Logger bug with PHP-Version -ge 5.4
- Fixed SeasLog::log('level','message','content',['logger']) bug
- Support SeasLog::analyzerDetail("all")
- Support SeasLog::analyzerCount("all")

附1:PECL項目主頁http://pecl.php.net/package/SeasLog

附2:GitHub項目主頁https://github.com/Neeke/SeasLog

SeasLog
Yet a log extension for PHP.A effective,fast,stable log extension for PHP
@author Chitao.Gao [neeke@php.net]

為什麼使用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 日誌介面規範

  • 自動記錄錯誤信息

  • 自動記錄異常信息

目標是怎樣的

  • 便捷、規範的log記錄

  • 高效的海量log分析

  • 可配置、多途徑的log預警

安裝

編譯安裝 seaslog

?
1
2
3
/path/to/phpize
$ ./configure --with-php-config=/path/to/php-config
make && make install

seaslog.ini 的配置

?
1
2
3
4
5
6
7
8
9
10
11
; configuration for php SeasLog module
extension = seaslog.so
seaslog.default_basepath = /log/seaslog-test    ;默認log根目錄
seaslog.default_logger = default                ;默認logger目錄
seaslog.disting_type = 1                        ;是否以type分文件 1是 0否(默認)
seaslog.disting_by_hour = 1                     ;是否每小時劃分一個文件 1是 0否(默認)
seaslog.use_buffer = 1                          ;是否啟用buffer 1是 0否(默認)
seaslog.buffer_size = 100                       ;buffer中緩衝數量 默認0(不使用buffer_size)
seaslog.level = 0                               ;記錄日誌級別 默認0(所有日誌)
seaslog.trace_error = 1                         ;自動記錄錯誤 默認1(開啟)
seaslog.trace_exception = 0                     ;自動記錄異常信息 默認0(關閉)

       seaslog.disting_type = 1 開啟以type分文件,即log文件區分info\warn\erro

seaslog.disting_by_hour = 1 開啟每小時劃分一個文件

seaslog.use_buffer = 1 開啟buffer。默認關閉。當開啟此項時,日誌預存於內存,當請求結束時(或異常退出時)一次寫入文件。

常量與函數

常量列表

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
* SEASLOG_DEBUG                       "debug"
* SEASLOG_INFO                        "info"
* SEASLOG_NOTICE                      "notice"
* SEASLOG_WARNING                     "warning"
* SEASLOG_ERROR                       "error"
* SEASLOG_CRITICAL                    "critical"
* SEASLOG_ALERT                       "alert"
* SEASLOG_EMERGENCY                   "emergency"
 
 
var_dump(SEASLOG_DEBUG,SEASLOG_INFO,SEASLOG_NOTICE);
/*
string('debug') debug級別
string('info')  info級別
string('notice') notice級別
*/

   函數列表

SeasLog 提供了這樣一組函數,可以方便地獲取與設置根目錄、模塊目錄、快速寫入與統計log。 相信從下述偽代碼的註釋中,您可以快速獲取函數信息,具體使用將緊接其後:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
 * @author neeke@php.net
 * Date: 14-1-27 下午4:47
 */
 
 
class SeasLog
{
    public function __construct()
    {
        #SeasLog init
    }
 
 
    public function __destruct()
    {
        #SeasLog distroy
    }
 
 
    /**
     * 設置basePath
     * @param $basePath
     * @return bool
     */
    static public function setBasePath($basePath)
    {
        return TRUE;
    }
 
 
    /**
     * 獲取basePath
     * @return string
     */
    static public function getBasePath()
    {
        return 'the base_path';
    }
 
 
    /**
     * 設置模塊目錄
     * @param $module
     * @return bool
     */
    static public function setLogger($module)
    {
        return TRUE;
    }
 
 
    /**
     * 獲取最後一次設置的模塊目錄
     * @return string
     */
    static public function getLastLogger()
    {
        return 'the lastLogger';
    }
 
 
    /**
     * 統計所有類型(或單個類型)行數
     * @param $level
     * @param string $log_path
     * @return array | long
     */
    static public function analyzerCount($level 'all',$log_path '*')
    {
        return array();
    }
 
 
    /**
     * 以數組形式,快速取出某類型log的各行詳情
     * @param $level
     * @param string $log_path
     * @return array
     */
    static public function analyzerDetail($level = SEASLOG_INFO,$log_path '*')
    {
        return array();
    }
 
 
    /**
     * 獲得當前日誌buffer中的內容
     * @return array
     */
    static public function getBuffer()
    {
        return array();
    }
 
 
    /**
     * 記錄debug日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function debug($message,array $content array(),$module '')
    {
        #$level = SEASLOG_DEBUG
    }
 
 
    /**
     * 記錄info日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function info($message,array $content array(),$module '')
    {
        #$level = SEASLOG_INFO
    }
 
 
    /**
     * 記錄notice日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function notice($message,array $content array(),$module '')
    {
        #$level = SEASLOG_NOTICE
    }
 
 
    /**
     * 記錄warning日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function warning($message,array $content array(),$module '')
    {
        #$level = SEASLOG_WARNING
    }
 
 
    /**
     * 記錄error日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function error($message,array $content array(),$module '')
    {
        #$level = SEASLOG_ERROR
    }
 
 
    /**
     * 記錄critical日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function critical($message,array $content array(),$module '')
    {
        #$level = SEASLOG_CRITICAL
    }
 
 
    /**
     * 記錄alert日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function alert($message,array $content array(),$module '')
    {
        #$level = SEASLOG_ALERT
    }
 
 
    /**
     * 記錄emergency日誌
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function emergency($message,array $content array(),$module '')
    {
        #$level = SEASLOG_EMERGENCY
    }
 
 
    /**
     * 通用日誌方法
     * @param $level
     * @param $message
     * @param array $content
     * @param string $module
     */
    static public function log($level,$message,array $content array(),$module '')
    {
 
 
    }
}

SeasLog Logger的使用(詳細文檔)

使用SeasLog進行健康預警

預警的配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[base]
wait_analyz_log_path = /log/base_test
 
 
[fork]
;是否開啟多線程 1開啟 0關閉
fork_open = 1
 
 
;線程個數
fork_count = 3
 
 
[warning]
email[smtp_host] = smtp.163.com
email[smtp_port] = 25
email[subject_pre] = 預警郵件 -
email[smtp_user] = seaslogdemo@163.com
email[smtp_pwd] = seaslog#demo
email[mail_from] = seaslogdemo@163.com
email[mail_to] = gaochitao@weiboyi.com
email[mail_cc] = ciogao@gmail.com
email[mail_bcc] =
 
 
[analyz]
; enum
; SEASLOG_DEBUG      "debug"
; SEASLOG_INFO       "info"
; SEASLOG_NOTICE     "notice"
; SEASLOG_WARNING    "warning"
; SEASLOG_ERROR      "error"
; SEASLOG_CRITICAL   "critical"
; SEASLOG_ALERT      "alert"
; SEASLOG_EMERGENCY  "emergency"
 
 
test1[module] = test/bb
test1[level] = SEASLOG_ERROR
test1[bar] = 1
test1[mail_to] = gaochitao@weiboyi.com
 
 
test2[module] = 222
test2[level] = SEASLOG_WARNING
 
 
test3[module] = 333
test3[level] = SEASLOG_CRITICAL
 
 
test4[module] = 444
test4[level] = SEASLOG_EMERGENCY
 
 
test5[module] = 555
test5[level] = SEASLOG_DEBUG

crontab配置

?
1
2
;每天凌晨3點執行
0 3 * * * /path/to/php /path/to/SeasLog/Analyzer/SeasLogAnalyzer.php

Demo:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
/**
 * @author ciogao@gmail.com
 * Date: 14-1-27 下午4:41
 */  
 
SeasLog::log(SEASLOG_ERROR,'this is a error test by ::log');
 
SeasLog::debug('this is a {userName} debug',array('{userName}' => 'neeke'));
 
SeasLog::info('this is a info log');
 
SeasLog::notice('this is a notice log');
 
SeasLog::warning('your {website} was down,please {action} it ASAP!',array('{website}' => 'github.com','{action}' => 'rboot'));
 
SeasLog::error('a error log');
 
SeasLog::critical('some thing was critical');
 
SeasLog::alert('yes this is a {messageName}',array('{messageName}' => 'alertMSG'));
 
SeasLog::emergency('Just now, the house next door was completely burnt out! {note}',array('{note}' => 'it`s a joke'));
echo "\n";

[admin ] PHP日誌擴展 SeasLog-1.4.4 發布, 重要 bug 修復已經有566次圍觀

http://coctec.com/news/all/show-post-204841.html