[SOLVED]Passing Yii2 Exceptions to log4php

Hey folks,

i couldn’t find a solution for this so i thought i ask here on the forums.

i’m relatively new to yii2 so sorry if its easy question for you.

I was asking myself how can i pass the exception error thrown by yii to my log4php logger?

The only thing i found was that i can set up a yii logger in the config. The customers wish was to use log4php and they want to evaluate it through logFace. So i set it up and i can write my log messages but only where i manually wrote the logging command.

Now i need to log also the exceptions thrown through yii but i have no clue how to do it. Can i somehow say yii to use my log4php logger?

But in the end yii logger or log4php its only a different way to write to a file or send data to server, or not?

You can declare custom error handler in your config/main.php:





'components' => [

    ...

    'errorHandler' => [

        'class' => 'common\extra\CustomErrorHandler',

    ],

]




And add common\extra\CustomErrorHandler.php:





namespace common\extra;


use yii\web\ErrorHandler;


class CustomErrorHandler extends ErrorHandler

{

    function renderException($exception)

    {

        // Log exception

        ...

        // Render exception

        return parent::renderException($exception)

    }

}




wow thats it. Makes sense. thank you!