Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/leafsphp/logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Nov 6, 2024
2 parents 866f4eb + fbf454d commit 7bd1985
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/scripts.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php

if (class_exists('Leaf\Config')) {
\Leaf\Config::addScript(function ($app) {
$app->register('logWriter', function ($c) use ($app) {
$logWriter = $app->config('log.writer');
$file = $app->config('log.dir') . $app->config('log.file');

return is_object($logWriter) ? $logWriter : new \Leaf\LogWriter($file, $app->config('log.open') ?? true);
\Leaf\Config::addScript(function () {
\Leaf\Config::singleton('logWriter', function ($c) {
return is_object($c['log.writer']) ?
$c['log.writer'] :
new \Leaf\LogWriter($c['log.dir'] . $c['log.file'], $c['log.open'] ?? true);
});

$app->register('log', function ($c) use ($app) {
$log = new \Leaf\Log($c->logWriter);
$log->enabled($app->config('log.enabled'));
$log->level($app->config('log.level'));
\Leaf\Config::singleton('log', function ($c) {
$log = new \Leaf\Log(\Leaf\Config::get("logWriter"));
$log->enabled($c['log.enabled']);
$log->level($c['log.level']);

return $log;
});
Expand Down

0 comments on commit 7bd1985

Please sign in to comment.