Two appenders

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Two appenders

Jan Galler
Hi everyone,

I'm trying to create a logger that covers two outputs. The first one is 
a database (so every stuff should go there). And now I try to add an 
appender that sends every log-event with an level higher 'warn'.

But I really don't get it working?! I'm doing the following code (PHP):

Logger::configure(
array(
    'appenders' =3D> array(
        'default' =3D> array(
            'class' =3D> 'LoggerAppenderPDO',
            'params' =3D> array(
                'dsn' =3D> =
'mysql:host=3D'.$logHost.';port=3D'.$logPort.';dbname=3D'.$logName,
                'user' =3D> $logUser,
                'password' =3D> $logPass,
                'table' =3D> 'log4php_log',
            ),
         'default' =3D> array(
             'class' =3D> 'LoggerAppenderMailEvent',
             'layout' =3D> array(
                 'class' =3D> 'LoggerLayoutSimple',
             ),
             'params' =3D> array(
                 'to' =3D> '[hidden email]',
                 'from' =3D> '[hidden email]'
             ),
             'filters' =3D> array(
              array(
              'class' =3D> 'LoggerFilterLevelRange',
                     'params' =3D> array(
                      'levelMin' =3D> 'warn',
                         'levelMax' =3D> 'error',
                     )
              )
          )
         ),
           =20
        ),
    ),
    'rootLogger' =3D> array(
        'appenders' =3D> array('default'),
    ),

)
);


Can anyone advise me how to do that?



Best regards,
Jan Galler
Reply | Threaded
Open this post in threaded view
|

Re: Two appenders

Ivan Habunek
On 19 February 2013 21:23, Jan Galler <[hidden email]> wrote:
> Hi everyone,

Hi Jan!

> I'm trying to create a logger that covers two outputs. The first one is
> a database (so every stuff should go there). And now I try to add an
> appender that sends every log-event with an level higher 'warn'.
>
> But I really don't get it working?! I'm doing the following code (PHP):
>
> --snip--
>

Under 'appenders' you have an array with two identical keys, basically
you do this:

'appenders' => array(
    'default' => ...,
    'default' => ...,
)

So the second one overrides the first. You should name them
differently, e.g. 'dbappender' and 'emailappender' (or whatever else
you like).

Finally, to link both appenders to the root logger, do this:

'rootLogger' => array(
    'appenders' => array('dbappender', 'emailappender'),
),

Also, you don't need to use filters in this case, just set the
appender threshold to 'warn' and it will filter out levels under
'warn'. To do this, replace 'filters' with:
'threshold' => 'warn'

Here's the whole shebang:

Logger::configure(
    array(
        'appenders' => array(
            'dbappender' => array(
                'class' => 'LoggerAppenderPDO',
                'params' => array(
                    'dsn' =>
'mysql:host='.$logHost.';port='.$logPort.';dbname='.$logName,
                    'user' => $logUser,
                    'password' => $logPass,
                    'table' => 'log4php_log',
                ),
            ),
            'emailappender' => array(
                'class' => 'LoggerAppenderMailEvent',
                'layout' => array(
                    'class' => 'LoggerLayoutSimple',
                ),
                'params' => array(
                    'to' => '[hidden email]',
                    'from' => '[hidden email]'
                ),
                'threshold' => 'warn'
            ),
        ),
        'rootLogger' => array(
            'appenders' => array('dbappender', 'emailappender'),
        )
    )
);


Try it out and see if it works. ;)

Regards,
Ivan