fluent logger for laravel (with Monolog handler for Fluentd )
Require this package with Composer
$ composer require ytake/laravel-fluent-logger
or composer.json
"require": {
"ytake/laravel-fluent-logger": "~1.0"
},
your config/app.php
'providers' => [
\Ytake\LaravelFluent\LogServiceProvider::class,
]
- basic
$ php artisan vendor:publish
- use tag option
$ php artisan vendor:publish --tag=log
- use provider
$ php artisan vendor:publish --provider="Ytake\LaravelFluent\LogServiceProvider"
your Application service provider
public function boot()
{
$this->app['fluent.handler']->pushHandler();
}
in Application Http\Kernel class
override bootstrappers property
/**
* The bootstrap classes for the application.
*
* @var array
*/
protected $bootstrappers = [
'Illuminate\Foundation\Bootstrap\DetectEnvironment',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
\Ytake\LaravelFluent\ConfigureLogging::class,
'Illuminate\Foundation\Bootstrap\HandleExceptions',
'Illuminate\Foundation\Bootstrap\RegisterFacades',
'Illuminate\Foundation\Bootstrap\RegisterProviders',
'Illuminate\Foundation\Bootstrap\BootProviders',
];
in Application Console\Kernel class
override bootstrappers property
protected $bootstrappers = [
'Illuminate\Foundation\Bootstrap\DetectEnvironment',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
\Ytake\LaravelFluent\ConfigureLogging::class,
'Illuminate\Foundation\Bootstrap\HandleExceptions',
'Illuminate\Foundation\Bootstrap\RegisterFacades',
'Illuminate\Foundation\Bootstrap\SetRequestForConsole',
'Illuminate\Foundation\Bootstrap\RegisterProviders',
'Illuminate\Foundation\Bootstrap\BootProviders',
];
edit config/app.php
'log' => 'fluent',
## match tag=local.** (for laravel log develop)
<match local.**>
type stdout
</match>
example (production)
<match production.**>
type stdout
</match>
and more
required config/compile.php
'providers' => [
//
\Ytake\LaravelFluent\LogServiceProvider::class,
],
Extend \Laravel\Lumen\Application and override the getMonologHandler() method to set up your own logging config.
example
<?php
namespace App\Foundation;
use Monolog\Logger;
use Fluent\Logger\FluentLogger;
use Ytake\LaravelFluent\FluentHandler;
class Application extends \Laravel\Lumen\Application
{
/**
* @return FluentHandler
*/
protected function getMonologHandler()
{
return new FluentHandler(
new FluentLogger(env('FLUENTD_HOST', '127.0.0.1'), env('FLUENTD_PORT', 24224), []),
Logger::DEBUG
);
}
}
<match lumen.**>
type stdout
</match>
The code for laravel-fluent-logger is distributed under the terms of the MIT license.