Source of file Logging.php
Size: 2,949 Bytes - Last Modified: 2021-12-24T06:34:53+00:00
/var/www/docs.ssmods.com/process/src/src/Helper/Logging.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | <?php namespace SilverStripe\Omnipay\Helper; use Psr\Container\NotFoundExceptionInterface; use SilverStripe\Control\Director; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injector; class Logging { use Configurable; const LOGSTYLE_VERBOSE = 'verbose'; const LOGSTYLE_SIMPLE = 'simple'; const LOGSTYLE_FULL = 'full'; /** * The Gateway-Data logging style. Can be one of the following: * - 'full': Verbose logging, log all information. This will automatically turn into 'verbose' on a live environment! * - 'verbose': Verbose logging, but strips out sensitive information * - 'simple': Simplified messages * @var string * @config */ private static $logStyle = 'verbose'; /** * Field-Names that should be removed from the log * @var array * @config */ private static $loggingBlacklist = [ 'card', 'token', 'cvv' ]; /** * Get a logger * @return \Psr\Log\LoggerInterface */ public static function getLogger() { $logger = null; try { $logger = Injector::inst()->get('SilverStripe\Omnipay\Logger'); } catch (NotFoundExceptionInterface $e) { /* no op */ } return $logger; } /** * @return \Psr\Log\LoggerInterface */ public static function getExceptionLogger() { $logger = null; try { $logger = Injector::inst()->get('SilverStripe\Omnipay\ExceptionLogger'); } catch (NotFoundExceptionInterface $e) { /* no op */ } return $logger; } /** * Prepare data for logging by cleaning up the data or simplify it. * @param mixed $data the incoming data to log * @return array processed data for logging */ public static function prepareForLogging($data) { if (empty($data)) { return []; } // If not an array, wrap it as an array if (!is_array($data)) { return [$data]; } if (self::config()->logStyle == self::LOGSTYLE_SIMPLE) { return array_filter([ isset($data['Message']) ? $data['Message'] : null, isset($data['Code']) ? $data['Code'] : null ]); } if (Director::isLive() || self::config()->logStyle == self::LOGSTYLE_VERBOSE) { self::sanitize($data); } return $data; } /** * Clean out sensitive data, such as credit-card numbers * @param array $data */ private static function sanitize(array &$data) { $blackList = array_combine(self::config()->loggingBlacklist, self::config()->loggingBlacklist); array_walk_recursive($data, function (&$value, $key) use ($blackList) { if (isset($blackList[$key])) { $value = '(sanitized)'; } }); } } |