php 日志處理工具 SeasLog 的使用


首先附上seaslog github地址:

  https://github.com/Neeke/SeasLog/blob/master/README_zh.md

php官方文檔地址:

  https://www.php.net/manual/zh/class.seaslog.php

 

SeasLog是一個C語言編寫的PHP擴展,提供一組規范標准的功能函數,在PHP項目中方便、規范、高效地寫日志,以及快速地讀取和查詢日志。

 

一.什么是日志系統

1. 記錄系統運行時的信息

2. 系統日志、應用程序日志、安全日志

3. 日志功能不應該影響到用戶的正常使用

 

二.為什么需要日志功能

1. 了解系統運行情況

2. 記錄用戶操作信息

3. 收集數據

 

三.為什么選擇SeasLog

1. 高性能(C語言做的 先將日志寫入內存達到一定量再寫入文件比頻繁寫入文件好)。

2. 無需配置

3. 功能完善、

4. 使用簡單

 

四.安裝SeasLog

pecl install seaslog

 

五.配置SeasLog

通過修改php.ini,修改seaslog配置

[seaslog]
seaslog.default_basepath = /home/www/log/               ;默認log根目錄
seaslog.default_logger = seaslog                        ;默認logger目錄
seaslog.disting_type = 0                                ;是否以type分文件 1是 0>否(默認)
seaslog.disting_by_hour = 0                             ;是否每小時划分一個文件 1是 0否(默認)
seaslog.use_buffer = 1                                  ;是否啟用buffer 1是 0否(默認)
seaslog.buffer_size = 500                               ;buffer中緩沖數量 默認0(不使用buffer_size)
seaslog.level = 0                                       ;記錄日志級別 默認0(所有
日志)
seaslog.trace_error = 1                                 ;自動記錄錯誤 默認1(開啟
)
seaslog.trace_exception = 0                             ;自動記錄異常信息 默認0(關閉)
seaslog.default_datetime_format = "Y:m:d H:i:s"         ;日期格式配置 默認"Y:m:d H:i:s"
seaslog.appender = 1                                    ;日志存儲介質 1File 2TCP 3UDP (默認為1)
seaslog.remote_host = 127.0.0.1                         ;接收ip 默認127.0.0.1 (>當使用TCP或UDP時必填)
seaslog.remote_port = 514                               ;接收端口 默認514 (當使>用TCP或UDP時必填)
seaslog.trim_wrap = 0                                   ;過濾日志中的回車和換行>符 (默認為0)

 

六.使用

SeasLog {
/* 方法 */
public static alert ( string $message [, array $content [, string $logger ]] ) : bool
public static analyzerCount ( string $level [, string $log_path [, string $key_word ]] ) : mixed
public static analyzerDetail ( string $level [, string $log_path [, string $key_word [, int $start [, int $limit [, int $order ]]]]] ) : mixed
public static closeLoggerStream ( int $model , string $logger ) : bool
public static critical ( string $message [, array $content [, string $logger ]] ) : bool
public static debug ( string $message [, array $content [, string $logger ]] ) : bool
public __destruct ( void )
public static emergency ( string $message [, array $content [, string $logger ]] ) : bool
public static error ( string $message [, array $content [, string $logger ]] ) : bool
public static flushBuffer ( void ) : bool
public static Seaslog::getBasePath ( void ) : string
public static getBuffer ( void ) : array
public static getBufferEnabled ( void ) : bool
public static getDatetimeFormat ( void ) : string
public static getLastLogger ( void ) : string
public static getRequestID ( void ) : string
public static getRequestVariable ( int $key ) : bool
public static info ( string $message [, array $content [, string $logger ]] ) : bool
public static log ( string $level [, string $message [, array $content [, string $logger ]]] ) : bool
public static notice ( string $message [, array $content [, string $logger ]] ) : bool
public static setBasePath ( string $base_path ) : bool
public static setDatetimeFormat ( string $format ) : bool
public static setLogger ( string $logger ) : bool
public static setRequestID ( string $request_id ) : bool
public static setRequestVariable ( int $key , string $value ) : bool
public static warning ( string $message [, array $content [, string $logger ]] ) : bool
}

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM