gpt4 book ai didi

laravel - 如何将日志事件从 Laravel 发送到 Loggly?

转载 作者:行者123 更新时间:2023-12-04 16:58:56 25 4
gpt4 key购买 nike

我想将 Monolog 日志从我的 Laravel 5.1 应用程序发送到 Loggly.com 在线日志管理服务。来自所有可能的环境,包括本地开发。

最佳答案

我发现了一些过时的库和复杂的方法来做到这一点。所以我最终得到了非常简单的解决方案。实际上,Laravel Monolog Handler 已经开箱即用了 Loggly Handler。

将配置信息添加到 config/services.php:

'loggly' => array(
'key' => 'ENTER_YOUR_LOGGLY_TOKEN_HERE',
'tag' => 'ProjectName_' .strtolower(env('APP_ENV')),
),

在返回 $app 之前,在 bootstrap/app.php 中添加 Monolog 处理程序:
/*
|--------------------------------------------------------------------------
| Setup Loggly Handler
|--------------------------------------------------------------------------
*/
$app->configureMonologUsing(function($monolog) {
$handler = new \Monolog\Handler\LogglyHandler(config('services.loggly.key'),\Monolog\Logger::DEBUG);
$handler->setTag(config('services.loggly.tag'));

$monolog->pushHandler($handler);
});

瞧!您正在 Loggly 仪表板中获取 Monolog 日志。

更新: (感谢@thitami)

基于 laravel.com/docs/5.6/upgrade

The configureMonologUsing Method If you were using the configureMonologUsing method to customize the Monolog instance for your application, you should now create a custom Log channel. For more information on how to create custom channels, check out the full logging documentation.

关于laravel - 如何将日志事件从 Laravel 发送到 Loggly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36259943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com