-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b161bb0
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; |