Skip to content

Commit

Permalink
Merge pull request #9 from rejoice-framework/master-dev
Browse files Browse the repository at this point in the history
logging to the right folder
  • Loading branch information
prinx authored May 7, 2021
2 parents bff7782 + 48ce5d2 commit 9f0e638
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Menu/BaseMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,39 @@ public function log($data, $level = 'info')
public function logger()
{
if (!$this->logger) {
$dir = $this->app->path('log_root_dir').'menus/'.date('Y-m-d');
$dir = Os::toPathStyle($dir);
$rootDir = $this->app->path('project_root');
$menuClassDir = $this->app->path('app_menu_class_dir');

$menuClassDirRelative = substr_replace($menuClassDir, '', 0, strlen($rootDir));

$menuClassDirRelativeExploded = explode(Os::slash(), $menuClassDirRelative);
$menuClassDirRelativeExploded = array_filter($menuClassDirRelativeExploded, function ($folder) {
return trim($folder);
});
$menuClassDirRelativeExploded = array_map(function ($folder) {
return ucfirst($folder);
}, $menuClassDirRelativeExploded);

$menuClassDirRelative = implode('\\', $menuClassDirRelativeExploded);

$exploded = explode($this->app->menuNamespaceDelimiter(), $this->name);
$menuName = substr_replace($this->name, '', 0, strlen($menuClassDirRelative.'\\'));

$exploded = explode($this->app->menuNamespaceDelimiter(), $menuName);

$menuName = Str::pascalCase(array_pop($exploded));
$menuRelativePath = $exploded ? implode(Os::slash(), $exploded) : '';
$dir = !$menuRelativePath ?: $dir.'/'.$menuRelativePath;

$dir = $this->app->path('log_root_dir').'menus/'.date('Y-m-d');
$dir = Os::toPathStyle($dir);
$dir = !$menuRelativePath ? $dir : $dir.'/'.$menuRelativePath;

if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}

$file = $dir.'/'.$menuName.'.log';
$cache = $dir.'/.count';

$this->logger = new Log($file, $cache);
}

Expand Down

0 comments on commit 9f0e638

Please sign in to comment.