diff --git a/composer.json b/composer.json index 743d383..9d9e04a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,10 @@ "autoload": { "psr-4": { "Leaf\\": "src" - } + }, + "files": [ + "src/scripts.php" + ] }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/src/scripts.php b/src/scripts.php new file mode 100644 index 0000000..7ddf316 --- /dev/null +++ b/src/scripts.php @@ -0,0 +1,20 @@ +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); + }); + + $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')); + + return $log; + }); + }); +}