Search code examples
laravelgoogle-cloud-platformlumenstackdrivergoogle-cloud-stackdriver

Stackdriver with PHP Lumen on Google App Engine Standard


my purpose is to manage the logs of my application with Google Stackdriver. The application is a lumen 5.8. Actually it works locally, but if deployed on my Google App Engine application it doesn't give back any error, but no logs are reported. There the steps:

  1. Install Google Cloud package
composer require google/cloud
  1. Create my Stackdriver logger class
<?php

namespace App\Logging;

use Google\Cloud\Logging\LoggingClient;
use Monolog\Handler\PsrHandler;
use Monolog\Logger;

class CreateStackdriverLogger
{
    /**
     * Create a custom Monolog instance.
     *
     * @param  array  $config
     * @return \Monolog\Logger
     */
    public function __invoke(array $config)
    {
        putenv('GOOGLE_APPLICATION_CREDENTIALS=' . config('google.service_account.filepath'));

        $logger = LoggingClient::psrBatchLogger('app');
        $handler = new PsrHandler($logger);

        return new Logger('stackdriver', [$handler]);
    }
}

  1. Create my config file logging.php in my app/config folder
<?php

use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
use App\Logging\CreateStackdriverLogger;

return [

    'channels' => [
        'stackdriver' => [
            'driver' => 'custom',
            'via' => CreateStackdriverLogger::class,
            'level' => 'debug',
        ],
...

  1. Register my loggin.php config file in app/bootstrap/app.php
$app->configure('logging');

What am I doing wrong?


Solution

  • Got it. The problem was in my php.ini :

    extension=grpc.so
    extension=protobuf.so
    extension=mongodb.so
    

    removing grpc.so and protobuf.so it turned back to work properly