【问题标题】:How to integrate Monolog in the Silex-WebProfiler?如何在 Silex-WebProfiler 中集成 Monolog?
【发布时间】:2013-09-10 15:30:10
【问题描述】:

我目前正在使用带有 Monolog 的 Silex 框架作为日志记录机制。通过使用以下组件 - https://github.com/silexphp/Silex-WebProfiler (Silex-WebProfiler),我能够成功地将默认的 Symfony WebProfiler 集成到我的项目中。它可以工作,但不幸的是它无法从其 _profiler 页面显示来自 Monolog 的日志消息。有人知道如何解决这个问题吗?

如果相关的话,这是我的配置:

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
    ));    
}

【问题讨论】:

    标签: php symfony silex monolog


    【解决方案1】:

    我也想知道这一点,我在 MonologServiceProvider 中找到了这些行。

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

    Web Profiler 的日志记录由 Symfony Monolog Bridge 组件启用。我将此添加到我的composer.json

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

    现在我在 Web Profiler 的那个面板中看到了日志条目。 (最好确保 monolog-bridge 的版本与您在 composer.json 中声明的其他 Symfony 组件的版本一致。)

    【讨论】:

    • 完美!!!作曲家中的 "symfony/monolog-bridge": "~2.3" 行完成了这项工作!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 2018-07-31
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多