How To Connect Laravel Lumen With Stackdriver

Viewed 536

Lumen application needs to be connected with GCP stackdriver. A new logger file in app\Logging is created with following contents

class AppStackdriverLogger
{
    public function __invoke(array $config)
    {
        // putenv("GOOGLE_APPLICATION_CREDENTIALS=/storage/app/iprocure-app.json");
        $logging = new LoggingClient([
            'projectId' => env('GOOGLE_CLOUD_PROJECT_ID'),
            'keyFilePath' => storage_path("app/iprocure-app.json"),
        ]);
        $logger = $logging->psrBatchLogger('app');

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

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

The logger file instantiate a new Logger that writes to GCP Stackdriver Logging And on the config\logging.php a custom handle is added like so

    'stackdriver' => [
        'driver' => 'custom',
        'via' => App\Logging\AppStackdriverLogger::class,
    ],

Which .env LOG_CHANNEL points to it.

The problem is when i try to log somewhere in the controller like so Log::debug("Somewhere in controller debug");, the request goes OK, but i dont see any log in Stackdriver Logging Logs Viewer How can Lumen application write logs to Stackdriver Logging.

0 Answers
Related