PHP code example of netflie / monolog-stackdriver-handler
1. Go to this page and download the library: Download netflie/monolog-stackdriver-handler library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
netflie / monolog-stackdriver-handler example snippets
use Netflie\MonologStackdriverHandler\MonologStackdriverHandler;
use Monolog\Logger;
// See Google\Cloud\Logging\LoggingClient::__construct
$loggingClientOptions = [
'keyFilePath' => '/path/to/service-account-key-file.json'
];
$monologStackdriverHandler = new MonologStackdriverHandler('my_log', $loggingClientOptions);
$monologLogger = new Logger('name');
$monologLogger->pushHandler($monologStackdriverHandler);
// Send records to Google Stackdriver Logging
$monologLogger->notice('Foo');
$monologLogger->error('Bar');
$loggerOptions = [
'batchEnabled' => true,
];
$monologStackdriverHandler = new MonologStackdriverHandler(
'my_log',
$loggingClientOptions,
$loggerOptions
);