Monolog Not Working!

I have implemented a basic logger like in 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
        )

)

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

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

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.

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

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’.

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 :wink: