日志
更新時間 2024-12-10 11:41:27
最近更新時間: 2024-12-10 11:41:27
分享文章
本文介紹如何在PHP運行環境下的日志打印。
打印日志
使用函數計算提供的全局日志對象打印日志
使用函數計算提供的全局日志對象 $GLOBALS['fcLogger'] 打印日志,使用該方法打印的每條日志中都包含日志級別、RequestId、時間等信息。示例代碼如下:
<?php
function handler($event, $context) {
$logger = $GLOBALS['fcLogger'];
$logger->info('hello info log');
$logger->critical('hello critical log');
$logger->setLevel(500);
$logger->info('hello info log');
$logger->critical('hello critical log');
return "hello world";
}
函數被執行后,會輸出以下日志:
2024-03-11 12:07:06 xxx [INFO] hello info log
2024-03-11 12:07:06 xxx [CRITICAL] hello critical log
2024-03-11 12:07:06 xxx [CRITICAL] hello critical log