简体   繁体   English

如何在Silex-WebProfiler中集成Monolog?

[英]How to integrate Monolog in the Silex-WebProfiler?

I am currently using the Silex Framework with Monolog as logging mechanism. 我目前正在使用带有Monolog的Silex Framework作为日志记录机制。 I was able to successfully integrate the default Symfony WebProfiler in my project by using the following component - https://github.com/silexphp/Silex-WebProfiler (Silex-WebProfiler). 通过使用以下组件 - https://github.com/silexphp/Silex-WebProfiler(Silex-WebProfiler ),我能够成功地将默认的Symfony WebProfiler集成到我的项目中。 It works, but unfortunately it cannot display the log messages from Monolog from its _profiler page. 它可以工作,但不幸的是它无法从其_profiler页面显示来自Monolog的日志消息。 Does someone know how to solve that issue? 有人知道如何解决这个问题吗?

Here is my configuration if that's relevant at all: 这是我的配置,如果这是相关的:

use Silex\Provider;
...
//Monolog
$app->register(new Provider\MonologServiceProvider(), array(
    'monolog.logfile' => __DIR__ . '/../log/development.log',
    'monolog.name'    => 'MyAppName'
));
...
// Web Profiler
if ($app['debug']) {
    $app->register(new Provider\WebProfilerServiceProvider(), array(
        'profiler.cache_dir' => __DIR__.'/../cache/profiler/',
        'profiler.mount_prefix' => '/_profiler', // this is the default
    ));    
}

I was wondering this, too, and I found these lines in MonologServiceProvider. 我也想知道这一点,我在MonologServiceProvider中找到了这些行。

if ($bridge = class_exists('Symfony\Bridge\Monolog\Logger')) {
    $app['monolog.handler.debug'] = function () use ($app) {
        return new DebugHandler($app['monolog.level']);
    };
}

The logging to the Web Profiler is enabled by the Symfony Monolog Bridge component. Symfony Monolog Bridge组件启用了对Web Profiler的日志记录。 I added this to my composer.json : 我把它添加到我的composer.json

"symfony/monolog-bridge": "~2.3"

Now I see log entries in that panel of the web profiler. 现在,我在Web Profiler的该面板中看到了日志条目。 (It's probably a good idea to make sure the version of the monolog-bridge is in line with the versions of other Symfony components you've declared in your composer.json .) (确保monolog-bridge的版本与您在composer.json声明的其他Symfony组件的版本一致,这可能是一个好主意。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM