記錄
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
PHP 用戶端程式庫符合 PSR-3 記錄標準,並提供 gRPC 呼叫的記錄器。
訊息的記錄層級取決於事件是否成功。
記錄訊息 |
成功狀態 |
失敗狀態 |
線上摘要 |
資訊 |
警告 |
偵錯訊息 (例如通話查詢) |
偵錯 |
注意事項 |
設定記錄
根據預設,每個程式庫記錄器都會使用 Monolog StreamHandler,在預設名稱指定的管道上,將記錄檔記錄至 STDERR
(詳情請參閱這裡)。
您可以在 google_ads_php.ini
檔案中設定預設記錄器的部分選項:
[LOGGING] ; Optional logging settings. logFilePath = "path/to/your/file.log"
logLevel = "INFO"
如需進一步自訂記錄,您可以提供實作 LoggerInterface
的記錄器,在 GoogleAdsClientBuilder
中完全指定自己的記錄器:
$googleAdsClient = (new GoogleAdsClientBuilder())
...
->withLogger(new MyCustomLogger())
->build();
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[[["\u003cp\u003eThe PHP client library uses PSR-3 for logging gRPC calls, with log levels varying based on success or failure of the event.\u003c/p\u003e\n"],["\u003cp\u003eBy default, logs are written to \u003ccode\u003eSTDERR\u003c/code\u003e using a Monolog StreamHandler with configurable options in the \u003ccode\u003egoogle_ads_php.ini\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eFor advanced customization, developers can implement the \u003ccode\u003eLoggerInterface\u003c/code\u003e and provide their own logger to the \u003ccode\u003eGoogleAdsClientBuilder\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eLogging is currently not supported for REST calls.\u003c/p\u003e\n"]]],[],null,["# Logging\n\n| **Note:** Logging is not supported for REST calls yet.\n\nThe PHP client library conforms to [PSR-3](http://www.php-fig.org/psr/psr-3) for\nlogging and provides a logger for gRPC calls.\n\nThe [level](//www.php-fig.org/psr/psr-3/#5-psrlogloglevel) at which messages are\nlogged depends on whether the event succeeded.\n\n| Log message | Success status | Failure status |\n|------------------------------------|----------------|----------------|\n| One-line summary | INFO | WARNING |\n| Debug message (e.g., call queries) | DEBUG | NOTICE |\n\n#### Configuring logging\n\nBy default, each of the library loggers logs to\n[`STDERR`](http://php.net/manual/en/features.commandline.io-streams.php) on a\nchannel with default name specified\n[here](https://github.com/googleads/google-ads-php/blob/HEAD/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsClientBuilder.php#L34)\nusing a [Monolog\nStreamHandler](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/StreamHandler.php).\n\nYou can configure some options for the default logger in the\n[`google_ads_php.ini`](https://github.com/googleads/google-ads-php/blob/HEAD/examples/Authentication/google_ads_php.ini)\nfile:\n\n\\[LOGGING\\] ; Optional logging settings. logFilePath = \"path/to/your/file.log\"\nlogLevel = \"INFO\"\n\nIf you need to further customize logging, you can specify your own logger\nentirely by providing a logger that implements the\n[`LoggerInterface`](//www.php-fig.org/psr/psr-3/) in\n[`GoogleAdsClientBuilder`](https://github.com/googleads/google-ads-php/blob/HEAD/src/Google/Ads/GoogleAds/Lib/V%0A21/GoogleAdsClientBuilder.php): \n\n $googleAdsClient = (new GoogleAdsClientBuilder())\n ...\n -\u003ewithLogger(new MyCustomLogger())\n -\u003ebuild();"]]