PMCORE-1335 ProcessMaker core should be use the native Laravel log mechanism.
This commit is contained in:
14
app/Foundation/Application.php
Normal file
14
app/Foundation/Application.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Foundation;
|
||||
|
||||
use Illuminate\Foundation\Application as BaseApplication;
|
||||
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
|
||||
protected function registerBaseServiceProviders(): void
|
||||
{
|
||||
parent::registerBaseServiceProviders();
|
||||
}
|
||||
}
|
||||
68
app/Log/LogManager.php
Normal file
68
app/Log/LogManager.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Log;
|
||||
|
||||
use Illuminate\Log\LogManager as BaseLogManager;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use ProcessMaker\Core\System;
|
||||
|
||||
class LogManager extends BaseLogManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the log connection configuration.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function configurationFor($name)
|
||||
{
|
||||
//default
|
||||
if (!Str::contains($name, ':')) {
|
||||
return parent::configurationFor($name);
|
||||
}
|
||||
|
||||
//extend channel
|
||||
$parse = explode(':', $name, 2);
|
||||
if (empty($parse[0])) {
|
||||
$parse[0] = config('logging.default');
|
||||
}
|
||||
$config = parent::configurationFor($parse[0]);
|
||||
if (!empty($parse[1])) {
|
||||
$config['name'] = $parse[1];
|
||||
}
|
||||
|
||||
//extends
|
||||
if (!defined('PATH_DATA') || !defined('PATH_SEP')) {
|
||||
return $config;
|
||||
}
|
||||
$sys = System::getSystemConfiguration();
|
||||
|
||||
//level
|
||||
if (!empty($sys['logging_level'])) {
|
||||
$levels = ['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'];
|
||||
$level = strtolower($sys['logging_level']);
|
||||
if (in_array($level, $levels)) {
|
||||
$config['level'] = $level;
|
||||
}
|
||||
}
|
||||
|
||||
//path
|
||||
$basePath = PATH_DATA . 'sites' . PATH_SEP . config('system.workspace') . PATH_SEP . 'log' . PATH_SEP;
|
||||
$config['path'] = $basePath . File::basename($config['path']);
|
||||
if (!empty($sys['logs_location'])) {
|
||||
$config['path'] = $sys['logs_location'];
|
||||
}
|
||||
|
||||
//days
|
||||
if (!empty($sys['logs_max_files'])) {
|
||||
$value = intval($sys['logs_max_files']);
|
||||
if ($value >= 0) {
|
||||
$config['days'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,19 @@ use Monolog\Formatter\LineFormatter;
|
||||
|
||||
class CustomizeFormatter
|
||||
{
|
||||
private $format = "<%level%> %datetime% %channel% %level_name%: %message% %context%\n";
|
||||
private $dateFormat = "M d H:i:s";
|
||||
|
||||
/**
|
||||
* Customize the given logger instance.
|
||||
*
|
||||
* @param \Illuminate\Log\Logger $logger
|
||||
* @param \Illuminate\Log\Logger $logger
|
||||
* @return void
|
||||
*/
|
||||
public function __invoke($logger)
|
||||
{
|
||||
foreach ($logger->getHandlers() as $handler) {
|
||||
$handler->setFormatter(new LineFormatter(null, null, true, true));
|
||||
$handler->setFormatter(new LineFormatter($this->format, $this->dateFormat, true, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Helpers\Workspace;
|
||||
use App\Log\LogManager;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
@@ -13,7 +17,13 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
App::bind('workspace', function() {
|
||||
return new Workspace();
|
||||
});
|
||||
|
||||
$this->app->singleton('log', function ($app) {
|
||||
return new LogManager($app);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user