我正在使用Google Cloud(GKE),我想将他们的系统用于日志和监视器(Stackdriver).我的项目是在php Symfony3下.我正在搜索如何登录到我的symfony项目的一些日志.
我看到有一个官方的lib:
https://github.com/GoogleCloudPlatform/google-cloud-php
还有一个PSR-3级:
http://googlecloudplatform.github.io/google-cloud-php/#/docs/v0.20.1/logging/psrlogger
我的问题是,如何将我的config.yml与monolog集成?
我通过执行以下操作来完成此操作:
composer require "google/cloud":"~0.20"
在配置中,我使用了自定义处理程序:
monolog: handlers: main: type: service id: stackdriver_handler
注册处理程序服务:
services: stackdriver_handler: class: Acme\MyBundle\Monolog\StackdriverHandler
这是我使用的处理程序类:
client = new LoggingClient( [ 'projectId' => $projectId, ] ); $this->name = $name; $this->level = $level; $this->bubble = $bubble; } /** * {@inheritdoc} */ public function handle(array $record) { if (!$this->isHandling($record)) { return false; } $this->getLogger($record['channel'])->log(strtolower($record['level_name']), $record['message'], $record['context']); return false === $this->bubble; } /** * @param $channel * * @return LoggerInterface */ protected function getLogger($channel) { if (!isset($this->loggers[$channel])) { $this->loggers[$channel] = $this->client->psrLogger($this->name, ['labels' => ['context' => $channel]]); } return $this->loggers[$channel]; } }