Skip to content

Commit

Permalink
init master
Browse files Browse the repository at this point in the history
  • Loading branch information
farzinft committed Dec 14, 2017
0 parents commit b161bb0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "farzinft/flog",
"description": "Customizing Laravel Log",
"authors": [
{
"name": "farzin fthi",
"email": "[email protected]"
}
],
"autoload":{
"psr-4": {
"Flog\\": "src/"
}
},
"require": {
"morilog/jalali": "^2.3"
}
}
62 changes: 62 additions & 0 deletions src/FlogServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Flog;

use Carbon\Carbon;
use Illuminate\Support\ServiceProvider;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Morilog\Jalali\JalaliServiceProvider;

class FlogServiceProvider extends ServiceProvider
{

public function boot()
{
$this->publishes([
__DIR__ . '/config/flog.php' => config_path('flog.php'),
]);

if (config('jalali_date')) {
$this->app->register(JalaliServiceProvider::class);
}
}

public function register()
{
$this->configureMonolog();
}

protected function configureMonolog()
{
$this->app->configureMonologUsing(function ($monolog) {

$logPath = config('flog.log_path');

$logStreamHandler = new StreamHandler($logPath);

$logFormat = config('flog.log_format');

$formatter = new LineFormatter($logFormat);

$logStreamHandler->setFormatter($formatter);

$dailyHandler = new RotatingFileHandler($logPath, config('flog.max_files'));

$dailyHandler->setFormatter($formatter);

$monolog->pushHandler($logStreamHandler);

$monolog->pushHandler($dailyHandler);

$monolog->pushProcessor(function ($record) {
$record['datetime'] = Carbon::now()->format('Y/m/d H:i:s');
if (config('flog.jalali_date')) {
$record['datetime'] = Carbon::now()->format('Y/m/d H:i:s') . ' | ' . jdate()->format('Y/m/d H:i:s');
}
return $record;
});
});
}
}
28 changes: 28 additions & 0 deletions src/config/flog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

return [


/**
* Log Path
*/
'log_path' => storage_path('logs/' . kebab_case(config('app.name')) . '.log'),


/**
* Log Format
*/
'log_format' => "%datetime% [%level_name%] (%channel%): %message% %context%\n",


/**
* Daily Log Max Files
*/
'max_files' => 5,


/**
* set jalali Date
*/
'jalali_date' => false
];

0 comments on commit b161bb0

Please sign in to comment.