Last active
January 27, 2022 13:26
-
-
Save enumag/baf1a36252b2cf6d3e11e83f825be0ed to your computer and use it in GitHub Desktop.
cloud_batch_logging.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types = 1); | |
use Google\Cloud\Logging\LoggingClient; | |
use Google\CloudFunctions\FunctionsFramework; | |
use GuzzleHttp\Psr7\Response; | |
use Psr\Http\Message\ResponseInterface; | |
use Psr\Http\Message\ServerRequestInterface; | |
FunctionsFramework::http( | |
'entrypoint', | |
function (ServerRequestInterface $request): ResponseInterface | |
{ | |
$logger = LoggingClient::psrBatchLogger( | |
'app', | |
[ | |
'clientConfig' => [ | |
'projectId' => getenv('GC_PROJECT'), | |
], | |
'resource' => [ | |
'type' => 'cloud_function', | |
'labels' => [ | |
'function_name' => getenv('GC_FUNCTION_NAME'), | |
'region' => getenv('GC_REGION'), | |
], | |
], | |
] | |
); | |
try { | |
// Do your cloud function logic here and use $logger for logging. | |
$logger->debug('Processing request...'); | |
return new Response(200, [], 'Hello world'); | |
} finally { | |
$logger->flush(); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment