<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 日志記錄(Logging) Phalcon提供了一個日志記錄組件即[Phalcon\\Logger](http://docs.iphalcon.cn/api/Phalcon_Logger.html)。 我們可以使用此組件輸出日志到不同的流中,如文件,系統日志等。 這個組件還提供了其它的功能如日志事務(類似于數據庫的事務), 配置選項, 還可以輸出不同的格式,另外還支持多種過濾器。[Phalcon\\Logger](http://docs.iphalcon.cn/api/Phalcon_Logger.html)提供了多種日志記錄方式,從調試程序到跟蹤應用的執行以滿足應用的需求。 ## 適配器(Adapters) 此組件使用不同的流適配器來保存日信息。 我們可以按需使用適配器。支持的適配器如下: | 適配器 | 描述 | | --- | --- | | [Phalcon\\Logger\\Adapter\\File](http://docs.iphalcon.cn/api/Phalcon_Logger_Adapter_File.html) | 保存日志到普通文件 | | [Phalcon\\Logger\\Adapter\\Stream](http://docs.iphalcon.cn/api/Phalcon_Logger_Adapter_Stream.html) | 保存日志到PHP流 | | [Phalcon\\Logger\\Adapter\\Syslog](http://docs.iphalcon.cn/api/Phalcon_Logger_Adapter_Syslog.html) | 保存到系統日志 | | [Phalcon\\Logger\\Adapter\\FirePHP](http://docs.iphalcon.cn/api/Phalcon_Logger_Adapter_Firephp.html) | 發送日志到FirePHP | ## 創建日志(Creating a Log) 下面的例子展示了如何創建日志對象及如何添加日志信息: ~~~ <?php use Phalcon\Logger; use Phalcon\Logger\Adapter\File as FileAdapter; $logger = new FileAdapter("app/logs/test.log"); // These are the different log levels available: $logger->critical( "This is a critical message" ); $logger->emergency( "This is an emergency message" ); $logger->debug( "This is a debug message" ); $logger->error( "This is an error message" ); $logger->info( "This is an info message" ); $logger->notice( "This is a notice message" ); $logger->warning( "This is a warning message" ); $logger->alert( "This is an alert message" ); // You can also use the log() method with a Logger constant: $logger->log( "This is another error message", Logger::ERROR ); // If no constant is given, DEBUG is assumed. $logger->log( "This is a message" ); // You can also pass context parameters like this $logger->log( "This is a {message}", [ 'message' => 'parameter' ] ); ~~~ 產生的日志信息如下: ~~~ [Tue, 28 Jul 15 22:09:02 -0500][CRITICAL] This is a critical message [Tue, 28 Jul 15 22:09:02 -0500][EMERGENCY] This is an emergency message [Tue, 28 Jul 15 22:09:02 -0500][DEBUG] This is a debug message [Tue, 28 Jul 15 22:09:02 -0500][ERROR] This is an error message [Tue, 28 Jul 15 22:09:02 -0500][INFO] This is an info message [Tue, 28 Jul 15 22:09:02 -0500][NOTICE] This is a notice message [Tue, 28 Jul 15 22:09:02 -0500][WARNING] This is a warning message [Tue, 28 Jul 15 22:09:02 -0500][ALERT] This is an alert message [Tue, 28 Jul 15 22:09:02 -0500][ERROR] This is another error message [Tue, 28 Jul 15 22:09:02 -0500][DEBUG] This is a message [Tue, 28 Jul 15 22:09:02 -0500][DEBUG] This is a parameter ~~~ You can also set a log level using the`setLogLevel()`method. This method takes a Logger constant and will only save log messages that are as important or more important than the constant: ~~~ <?php use Phalcon\Logger; use Phalcon\Logger\Adapter\File as FileAdapter; $logger = new FileAdapter("app/logs/test.log"); $logger->setLogLevel( Logger::CRITICAL ); ~~~ In the example above, only critical and emergency messages will get saved to the log. By default, everything is saved. ## 事務(Transactions) 保存日志到適配器如文件(文件系統)是非常消耗系統資源的。 為了減少應用性能上的開銷,我們可以使用日志事務。 事務會把日志記錄臨時的保存到內存中然后再 寫入到適配中(此例子中為文件),(這個操作是個原子操作) ~~~ <?php use Phalcon\Logger\Adapter\File as FileAdapter; // 生成日志新組件實例 $logger = new FileAdapter("app/logs/test.log"); // 開啟事務 $logger->begin(); // 添加消息 $logger->alert( "This is an alert" ); $logger->error( "This is another error" ); // 保存消息到文件中 $logger->commit(); ~~~ ## 使用多個處理程序進行日志記錄(Logging to Multiple Handlers) [Phalcon\\Logger](http://docs.iphalcon.cn/api/Phalcon_Logger.html)也可以同時保存日志信息到多個適配器中: ~~~ <?php use Phalcon\Logger; use Phalcon\Logger\Multiple as MultipleStream; use Phalcon\Logger\Adapter\File as FileAdapter; use Phalcon\Logger\Adapter\Stream as StreamAdapter; $logger = new MultipleStream(); $logger->push( new FileAdapter("test.log") ); $logger->push( new StreamAdapter("php://stdout") ); $logger->log( "This is a message" ); $logger->log( "This is an error", Logger::ERROR ); $logger->error( "This is another error" ); ~~~ 信息發送的順序和處理器(適配器)注冊的順序相同。 ## 信息格式(Message Formatting) 此組件使用 formatters 在信息發送前格式化日志信息。 支持下而后格式: | 適配器 | 描述 | | --- | --- | | [Phalcon\\Logger\\Formatter\\Line](http://docs.iphalcon.cn/api/Phalcon_Logger_Formatter_Line.html) | 文本方式格式化信息 | | [Phalcon\\Logger\\Formatter\\Firephp](http://docs.iphalcon.cn/api/Phalcon_Logger_Formatter_Firephp.html) | Formats the messages so that they can be sent to FirePHP | | [Phalcon\\Logger\\Formatter\\Json](http://docs.iphalcon.cn/api/Phalcon_Logger_Formatter_Json.html) | 使用JSON格式格式化信息 | | [Phalcon\\Logger\\Formatter\\Syslog](http://docs.iphalcon.cn/api/Phalcon_Logger_Formatter_Syslog.html) | 使用系統提供的格式格式化信息 | ### 行格式化處理(Line Formatter) 使用單行格式格式化信息。 默認的格式如下: ~~~ [%date%][%type%] %message% ~~~ 我們可以使用`setFormat()`來設置自定義格式。 下面是格式變量: | 變量 | 描述 | | --- | --- | | %message% | 待記錄的日志消息 | | %date% | 消息添加的時間 | | %type% | 消息類型(使用大寫) | 下面的例子中展示了如何修改日志格式: ~~~ <?php use Phalcon\Logger\Formatter\Line as LineFormatter; $formatter = new LineFormatter("%date% - %message%"); // 修改日志格式 $logger->setFormatter($formatter); ~~~ ### 自定義格式處理(Implementing your own formatters) 若要實現自定義的格式則要實現[Phalcon\\Logger\\FormatterInterface](http://docs.iphalcon.cn/api/Phalcon_Logger_FormatterInterface.html)接口, 這樣才能擴展已有的格式或創建自定義的格式 ## 適配器(Adapters) 下面的例子中展示了每種適配器的簡單用法: ### 數據流日志記錄器(Stream Logger) 系統日志保存消息到一個已注冊的有效的PHP流中。 這里列出了可用的流: here `\_: ~~~ <?php use Phalcon\Logger\Adapter\Stream as StreamAdapter; // 使用zlib壓縮流 $logger = new StreamAdapter("compress.zlib://week.log.gz"); // 發送消息到stderr $logger = new StreamAdapter("php://stderr"); ~~~ ### 文件日志記錄器(File Logger) 文件適配器保存所有的日志信息到普通的文件中。 默認情況下日志文件使用添加模式打開,打開文件后文件的指針會指向文件的尾端。 如果文件不存在,則會嘗試創建。 我們可以通過傳遞附加參數的形式來修改打開的模式: ~~~ <?php use Phalcon\Logger\Adapter\File as FileAdapter; // 使用寫模式打開 $logger = new FileAdapter( "app/logs/test.log", [ "mode" => "w", ] ); ~~~ ### Syslog 日志記錄器(Syslog Logger) 使用系統日志適配器。 由于操作系統的不同得到的日志也不盡相同: ~~~ <?php use Phalcon\Logger\Adapter\Syslog as SyslogAdapter; // 基本用法 $logger = new SyslogAdapter(null); // Setting ident/mode/facility 參數設置 $logger = new SyslogAdapter( "ident-name", [ "option" => LOG_NDELAY, "facility" => LOG_MAIL, ] ); ~~~ ### FirePHP 日志記錄器(FirePHP Logger) This logger sends messages in HTTP response headers that are displayed by[FirePHP](http://www.firephp.org/), a[Firebug](http://getfirebug.com/)extension for Firefox. ~~~ <?php use Phalcon\Logger; use Phalcon\Logger\Adapter\Firephp as Firephp; $logger = new Firephp(""); $logger->log( "This is a message" ); $logger->log( "This is an error", Logger::ERROR ); $logger->error( "This is another error" ); ~~~ ### 自定義適配器(Implementing your own adapters) 如果開發者想自定義新的日志組件則需實現此接口:[Phalcon\\Logger\\AdapterInterface](http://docs.iphalcon.cn/api/Phalcon_Logger_AdapterInterface.html)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看