leafsphp / leaf

🍁 The easiest way to create clean, simple but powerful web apps and APIs quickly
https://leafphp.dev
MIT License
1.07k stars 64 forks source link

Logger not working #141

Closed agarzon-orangerine closed 2 years ago

agarzon-orangerine commented 2 years ago

Describe the bug Looks like the logger is not working, followed the instructions in the doc.

To Reproduce Just by adding this line, to test the logger : app()->logger()->info('Hello');

Expected behavior It should create and write the log file (it is enabled and well defined in config/app.php, I'm using the core template v3), and yes "leafs/logger" is installed via composer.

Additional context The error : ` Error thrown with message "Cannot use object of type Leaf\Helpers\Container as array"

Stacktrace: leafsphp/leaf#10 Error in /app/vendor/leafs/leaf/src/App.php:168 leafsphp/leaf#9 Leaf\App:Leaf{closure} in /app/vendor/leafs/leaf/src/Helpers/Container.php:223 leafsphp/leaf#8 Leaf\Helpers\Container:Leaf\Helpers{closure} in /app/vendor/leafs/leaf/src/Helpers/Container.php:67 leafsphp/leaf#7 Leaf\Helpers\Container:get in /app/vendor/leafs/leaf/src/App.php:210 leafsphp/leaf#6 Leaf\App:__get in /app/vendor/leafs/leaf/src/App.php:292 leafsphp/leaf#5 Leaf\App:logger in /app/app/controllers/BrainController.php:25 leafsphp/leaf#4 App\Controllers\BrainController:facial in /app/vendor/leafs/router/src/Router/Core.php:489 leafsphp/leaf#3 call_user_func_array in /app/vendor/leafs/router/src/Router/Core.php:489 leafsphp/leaf#2 Leaf\Router\Core:invoke in /app/vendor/leafs/router/src/Router/Core.php:455 leafsphp/leaf#1 Leaf\Router\Core:handle in /app/vendor/leafs/router/src/Router/Core.php:386

0 Leaf\Router\Core:run in /app/public/index.php:130

`

mychidarko commented 2 years ago

I'm using the core template v3

Which template exactly is that @agarzon-orangerine? Leaf MVC, Leaf API or skeleton, or you scaffolded a basic Leaf app with Leaf CLI?

agarzon-orangerine commented 2 years ago

using leaf cli

On Fri, Aug 26, 2022, 6:20 p.m. Michael Darko @.***> wrote:

I'm using the core template v3

Which template exactly is that @agarzon-orangerine https://github.com/agarzon-orangerine? Leaf MVC, Leaf API or skeleton, or you scaffolded a basic Leaf app with Leaf CLI?

— Reply to this email directly, view it on GitHub https://github.com/leafsphp/leaf/issues/141, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR44IKMOEIILKWBSFTOQLGLV3E7JVANCNFSM57X5X7KQ . You are receiving this because you were mentioned.Message ID: @.***>

mychidarko commented 2 years ago

Can you maybe leave a screenshot of your directory structure? I'll check on replicating your issue

agarzon-orangerine commented 2 years ago

I was able to reproduce the problem with a fresh brand new leaf project:

PHP 8.1.2 (cli) (built: Aug 15 2022 12:24:10) (NTS)

leaf create leaf-test --api --v3 cd leaf-test leaf serve

Add this line to the router:

app()->logger()->debug('Hello!');

Same error. `Error thrown with message "Cannot use object of type Leaf\Helpers\Container as array"

Stacktrace:

11 Error in /home/agarzon/GIT/leaf-test/vendor/leafs/leaf/src/App.php:168

10 Leaf\App:Leaf{closure} in /home/agarzon/GIT/leaf-test/vendor/leafs/leaf/src/Helpers/Container.php:223

9 Leaf\Helpers\Container:Leaf\Helpers{closure} in /home/agarzon/GIT/leaf-test/vendor/leafs/leaf/src/Helpers/Container.php:67

8 Leaf\Helpers\Container:get in /home/agarzon/GIT/leaf-test/vendor/leafs/leaf/src/App.php:210

7 Leaf\App:__get in /home/agarzon/GIT/leaf-test/vendor/leafs/leaf/src/App.php:292

6 Leaf\App:logger in /home/agarzon/GIT/leaf-test/app/routes/_app.php:4

5 {closure} in /home/agarzon/GIT/leaf-test/vendor/leafs/router/src/Router/Core.php:471

4 call_user_func_array in /home/agarzon/GIT/leaf-test/vendor/leafs/router/src/Router/Core.php:471

3 Leaf\Router\Core:invoke in /home/agarzon/GIT/leaf-test/vendor/leafs/router/src/Router/Core.php:455

2 Leaf\Router\Core:handle in /home/agarzon/GIT/leaf-test/vendor/leafs/router/src/Router/Core.php:386

leafsphp/leaf#141 Leaf\Router\Core:run in /home/agarzon/GIT/leaf-test/public/index.php:130

0 require_once in /home/agarzon/GIT/leaf-test/index.php:24

` image

mychidarko commented 2 years ago

Thanks. This is very helpful

mychidarko commented 2 years ago

This issue has been fixed by @jeijei4. A patch release will be up soon to fix this. Thanks