# Monolog Not Working!

**URL:** <https://discourse.slimframework.com/t/monolog-not-working/2916>\
**Category:** Questions\
**Created:** [January 25, 2019, 4:56am UTC](https://discourse.slimframework.com/t/monolog-not-working/2916 "2019-01-25T04:56:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![drpayyne](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@drpayyne](https://discourse.slimframework.com/u/drpayyne)\
**Post date:** [January 25, 2019, 4:56am UTC](https://discourse.slimframework.com/t/monolog-not-working/2916/1 "2019-01-25T04:56:30Z")

</div>

I have implemented a basic logger like in [https://akrabat.com/logging-errors-in-slim-3/](https://akrabat.com/logging-errors-in-slim-3/). When I var\_dump($container[‘errorHandler’]), I get the following code. When I throw a new Exception(), I get no output in log file. Help!

```
App\Handlers\Error Object
(
    [logger:protected] => Monolog\Logger Object
        (
            [name:protected] => logger
            [handlers:protected] => Array
                (
                    [0] => Monolog\Handler\FingersCrossedHandler Object
                        (
                            [handler:protected] => Monolog\Handler\StreamHandler Object
                                (
                                    [stream:protected] => 
                                    [url:protected] => /var/www/html/slim-api/public/app.log
                                    [errorMessage:Monolog\Handler\StreamHandler:private] => 
                                    [filePermission:protected] => 
                                    [useLocking:protected] => 
                                    [dirCreated:Monolog\Handler\StreamHandler:private] => 
                                    [level:protected] => 100
                                    [bubble:protected] => 1
                                    [formatter:protected] => 
                                    [processors:protected] => Array
                                        (
                                        )

                                )

                            [activationStrategy:protected] => Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy Object
                                (
                                    [actionLevel:Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy:private] => 400
                                )

                            [buffering:protected] => 1
                            [bufferSize:protected] => 0
                            [buffer:protected] => Array
                                (
                                )

                            [stopBuffering:protected] => 1
                            [passthruLevel:protected] => 
                            [level:protected] => 100
                            [bubble:protected] => 1
                            [formatter:protected] => 
                            [processors:protected] => Array
                                (
                                )

                        )

                )

            [processors:protected] => Array
                (
                )

            [microsecondTimestamps:protected] => 1
            [exceptionHandler:protected] => 
        )

    [displayErrorDetails:protected] => 
    [knownContentTypes:protected] => Array
        (
            [0] => application/json
            [1] => application/xml
            [2] => text/xml
            [3] => text/html
        )

)
```

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [January 26, 2019, 12:21pm UTC](https://discourse.slimframework.com/t/monolog-not-working/2916/2 "2019-01-26T12:21:47Z")

</div>

Looks like you’ve got the right object, so you will need to show us more code about your setup.

---

<div class="post-metadata">

**Author:** ![drpayyne](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@drpayyne](https://discourse.slimframework.com/u/drpayyne)\
**Post date:** [January 30, 2019, 12:18pm UTC](https://discourse.slimframework.com/t/monolog-not-working/2916/3 "2019-01-30T12:18:23Z")

</div>

> **[drpayyne/slim-api](https://github.com/drpayyne/slim-api)**
>
> A small project to test out Slim framework. Contribute to drpayyne/slim-api development by creating an account on GitHub.

Please check the above link.  
UPDATED COMMENT, CHECK BELOW.

---

<div class="post-metadata">

**Author:** ![drpayyne](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@drpayyne](https://discourse.slimframework.com/u/drpayyne)\
**Post date:** [January 31, 2019, 9:40am UTC](https://discourse.slimframework.com/t/monolog-not-working/2916/4 "2019-01-31T09:40:05Z")

</div>

I’ve simplified the above project and made it work. BUT, it works only on ‘php -S localhost:3000’ and not on default apache server. The location of this directory is ‘/var/www/html/’. What could be the reason that monolog and Slim error handle be working in CMD server and not apache? I get an empty response when error is throw, btw.

Without errors, the project is working on both types.

> **[drpayyne/slim-api](https://github.com/drpayyne/slim-api/tree/redo)**
>
> A small project to test out Slim framework. Contribute to drpayyne/slim-api development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![jDolba](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jdolba/32/815_2.png) [@jDolba](https://discourse.slimframework.com/u/jDolba)\
**Post date:** [February 1, 2019, 12:42am UTC](https://discourse.slimframework.com/t/monolog-not-working/2916/5 "2019-02-01T00:42:11Z")

</div>

I think you need to implement also ‘phpErrorHandler’ in container?

> <https://stackoverflow.com/questions/49684070/why-is-slim-frameworks-phperrorhandler-not-working/54301281#54301281>

---

<div class="post-metadata">

**Author:** ![drpayyne](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@drpayyne](https://discourse.slimframework.com/u/drpayyne)\
**Post date:** [February 1, 2019, 2:13pm UTC](https://discourse.slimframework.com/t/monolog-not-working/2916/6 "2019-02-01T14:13:00Z")

</div>

No, I don’t think that’s the issue. For example, when I make my code throw an Exception, the Exception is caught and logger is run WHEN I run server using ‘php -S localhost:3000’ and NOT WHEN it’s run from apache2 server. Directory is ‘/var/www/html’.

---

<div class="post-metadata">

**Author:** ![jDolba](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jdolba/32/815_2.png) [@jDolba](https://discourse.slimframework.com/u/jDolba)\
**Post date:** [February 2, 2019, 12:50am UTC](https://discourse.slimframework.com/t/monolog-not-working/2916/7 "2019-02-02T00:50:02Z")

</div>

just add this somewhere to your public/index.php (before new App() for example)

```
 ini_set("error_log", __DIR__. '/../logs/app.log');

```

I have tried that on your repo 😉
