Update path of log files

This commit is contained in:
printempw 2018-07-21 23:17:27 +08:00
parent b047ee8fda
commit bf9342847f
4 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php
namespace App\Providers;
use Log;
use Illuminate\Support\ServiceProvider;
class LogServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Log::getMonolog()->popHandler();
Log::useFiles($this->getLogPath());
if (! config('app.debug')) {
$this->deleteLogs();
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
protected static function getLogPath()
{
$mask = substr(md5(implode(',', array_values(get_db_config()))), 0, 16);
return storage_path("logs/bs-$mask.log");
}
protected function deleteLogs()
{
@unlink($this->getLogPath());
@unlink(storage_path('logs/laravel.log'));
}
}

View File

@ -168,6 +168,7 @@ return [
*/
App\Providers\BootServiceProvider::class,
App\Providers\AppServiceProvider::class,
App\Providers\LogServiceProvider::class,
App\Providers\PluginServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\MemoryServiceProvider::class,

View File

@ -1,2 +1,3 @@
*
!.gitignore
!index.html

0
storage/logs/index.html Normal file
View File