codeinternetapplications / monolog-stackdriver

Stackdriver handler for Monolog.
MIT License
15 stars 15 forks source link

monolog-stackdriver running on Google App Engine : be able to use empty constructor and rely on env vars #4

Closed dev-mansonthomas closed 5 years ago

dev-mansonthomas commented 5 years ago

Hi,

When I'm using the google API, I don't provide the project ID or the json path, I just instantiate the object with an empty constructor :

$pubsub = new PubSub();

And the google API will get from the env variables of the AppEngine / (or one that I've set manually on my local dev machine). GOOGLE_CLOUD_PROJECT, GOOGLE_APPLICATION_CREDENTIALS

putenv("GOOGLE_APPLICATION_CREDENTIALS=/Users/thomas/.proj/project-fr-dev-3536b42e73ef.json"); (it's enough, I didn't set the GOOGLE_CLOUD_PROJECT)

With monolog-stackdriver, I've tried to use an empty constructor and got an error.

It would be nice to be able to instantiate the monolog_strackdriver with an empty constructor.

Side note: using StackDriver locally slow down a lot the application. It put a 3 secondes response time delay each time the logger is used. I didn't tried yet in an AppEngine, but It feel bad for performances.

martinatcode commented 5 years ago

Hello Thomas,

As we work with Laravel Lumen, we already omit the loggingClientOptions while using the environment variables you named. I never had a look on this for other frameworks that instantiate this class differently. So you're spot on!

There's just an update pushed to develop where you're allowed to omit the second argument. The first argument is still required to give the log a name as it will appear in the 'global' section of Stackdriver. I saw the naming of that variable was incorrect, that's fixed as well.

Maybe you can help me out testing the develop branch as I have little time.

The slowness is indeed an annoying thing. We tend to use Stackdriver only on severities higher then "warning". For others, we use a file based log driver instead to minimise the delays.

With kind regards, Martin

dev-mansonthomas commented 5 years ago

Hi Martin,

In the meantime, I've removed Monolog and switch to the LoggingClient directly.

Reading the doc, I saw an option that could improve the performance : the Batch Option, that stack all logging request into one call.

https://cloud.google.com/logging/docs/setup/php

The setup advise the installation of the following PECL extensions :

http://googleapis.github.io/google-cloud-php/#/docs/cloud-logging/v1.9.1/logging/loggingclient?method=__construct

And indeed, it speeded up the logging from my dev environment. So maybe you can add this as an option ($options['batchEnabled'] = true;)

I'm initiating my LoggingClient as follow, but I'm still looking how to fully configure it (see: https://stackoverflow.com/questions/54406075/stackdriver-in-php-how-to-setup-the-loggingclient-for-google-appengine-php-fle )

/**
 * pecl install grpc
 * pecl install protobuf
 *
 * @property PsrLogger    $logger
 * @param \Slim\Container $c
 * @return PsrLogger
 */
$container['logger'] = function (\Slim\Container $c)
{
  $settings = $c->get('settings')['logger'];

  $logger = LoggingClient::psrBatchLogger(
    $settings['name'], [
    'resource'=>[
      'type'=>'gae_app'
    ],
    'labels'  =>null
  ]);
  return $logger;
};