monolog
monolog copied to clipboard
Is there anyone who can show logs on Google Cloud Logging with Monolog v2?
Monolog version 1|2|3?
2 (2.8.0)
Write your question here.
I can output logs on Google Cloud Logging using Monolog v1. But after updating to v2, my system stopped outputting logs.
My code follows this doc. https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine/standard/laravel-framework
PHP8.1 requires Monolog v2. So I'd like to know whether there's anyone who can use Google Cloud Logging with Monolog v2.
Thanks
Environment
- php: 8.1
- laravel/framework: v8.83.23
- monolog: 2.8.0
- google/cloud: v0.188.0
- google/cloud-logging: 1.24.7 (included in google/cloud)
Might be related to those PRs? => https://github.com/Seldaek/monolog/pulls?q=is%3Apr+sort%3Aupdated-desc+gcp+
Thanks for your reply!
I don't think so. I've never seen any logs, including wrong formatted logs, on Google Cloud Logging with Monolog v2.
I set LOG_CHANNEL as stackdriver.
'stackdriver' => [
'driver' => 'custom',
'via' => App\Logging\CreateStackdriverLogger::class,
],
CreateStackdriverLogger.php is
<?php
namespace App\Logging;
use Monolog\Logger;
use Google\Cloud\Logging\LoggingClient;
use Monolog\Handler\PsrHandler;
use Monolog\Formatter\MyGoogleCloudLoggingFormatter;
class CreateStackdriverLogger
{
public function __invoke(array $config)
{
$logName = isset($config['logName']) ? $config['logName'] : 'app';
$psrLogger = LoggingClient::psrBatchLogger($logName);
$handler = new PsrHandler($psrLogger);
$handler->setFormatter(new MyGoogleCloudLoggingFormatter());
$logger = new Logger($logName, [$handler]);
return $logger;
}
}
I follow the steps written in this doc. It uses Monolog v1. https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine/standard/laravel-framework It works well with Monolog v1. But It hasn't worked well since updating the Monolog version from 1 to 2. (Laravel 8 requires Monolog v2)
So I'd like to know whether there is anyone who can see the logs on Google Cloud Logging with Monolog v2. And if there is, I'll be so happy if he/she tells me what's wrong with my code.
Thanks
I solved this problem.
First of all, the following document doesn't work with Monolog v2. https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine/standard/laravel-framework
This example works with Monolog v1. But we have to use Monolog v2 with Laravel v8. Then this tutorial doesn't work.
In those cases, the following are your go-to documents. https://cloud.google.com/appengine/docs/standard/php-gen2/writing-application-logs https://cloud.google.com/logging/docs/setup/php#creating_a_psr-3_logger
For more info, I found that
- psrBatchLogger doesn't work
- formatters don't work
I'm happy if this will help you.