Skip to content

Using custom logger class with CSRF Protector

minhaz edited this page Mar 17, 2018 · 1 revision

New parameter in init method

The csrfProtector::init method now accepts an additional optional parameter $logger

public static function init($length = null, $action = null, $logger = null) {

This is supposed to be an object of a class that implements the LoggerInterface interface.

interface LoggerInterface {
    public function log($message, $context = array());
}

In case the parameter is not provided - the default file based logger - csrfpDefaultLogger is used;

Using a custom logger which let's say send data to some slack channel

class CustomLogger implements LoggerInterface {
    public function log($message, $context = array()) {
        //// send the message to the slack channel :D
    }
}

//// Initialize the library with this logger
csrfProtector::init(null, null, new CustomLogger());