public function testLogMessageWithCustomFormatter() { $logger = new Logger(new PlainTextFormatter()); $logger->log('Foo Bar', new XmlFormatter()); $logger->log('Bar Foo', new XmlFormatter()); $logs = $logger->getLogs(); $this->assertCount(2, $logs); $this->assertRegExp('#<log time="\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}">Foo Bar<\\/log>#', $logs[0]); $this->assertRegExp('#<log time="\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}">Bar Foo<\\/log>#', $logs[1]); }
/** * Performs an authentication attempt * * @return \Zend\Authentication\Result * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface If authentication cannot be performed */ public function authenticate() { if (!$this->userId) { throw new EmptyCredentialsException("C'mon! It's a test things, user ID just cannot be null."); } Logger::getLogger(__CLASS__)->alert("Be sure it's only for testing: user #{$this->userId} was authenticated without credentials."); return new Result(Result::SUCCESS, $this->userId); }
function __construct($login = null, $password = null, $options = array()) { $this->login = $login; $this->password = $password; if ($options) { $this->setOptions($options); } static::$logger = Logger::getLogger(__CLASS__); }
/** * @param array $eventMap * @param null|EventManager $manager */ function __construct($eventMap = array(), $manager = null) { $this->eventMap = $eventMap; $this->manager = $manager; if ($this->manager === null) { $this->manager = new EventManager(); } $this->logger = \Logger\Logger::getLogger(__CLASS__); }
public function loadLogger(EventInterface $e) { if (!self::$ready) { self::$ready = true; /** @var \Zend\Mvc\Application $application */ $application = $e->getTarget(); $config = $application->getServiceManager()->get('Config'); if (isset($config['logger'])) { Logger::load($config['logger']); } } }
/** * Initialize * * @param $instance * @param ServiceLocatorInterface $serviceLocator * @throws \Acl\Exception\AccessDeniedException * @return mixed */ public function initialize($instance, ServiceLocatorInterface $serviceLocator) { if ($instance instanceof SecureControllerInterface) { /** @var Acl $acl */ $acl = $serviceLocator->get('dao-acl.service.default_factory'); /** @var AuthenticationServiceInterface $auth */ $auth = $serviceLocator->get('dao-auth.service.default_factory'); if ($auth->hasIdentity()) { $acl->setUserId($auth->getIdentity()); } if (!$acl->isAllowed($instance->getPrivileges())) { Logger::getLogger(__CLASS__)->notice("ACL Exception: access denied!"); throw new AccessDeniedException("Access denied!"); } } }
/** * @param null|AdapterOptions $adapterName * @param array $options * @throws Exception\RuntimeException * @return Acl */ public static function getInstance($adapterName = null, $options = array()) { if (static::$instance === null) { static::$logger = Logger::getLogger(__CLASS__); if ($adapterName instanceof AdapterInterface) { $adapter = $adapterName; } else { $adapter = static::getAdapterManager()->get($adapterName); } if ($options) { $adapter->setOptions($options); } static::$instance = new self($adapter); } elseif ($adapterName !== null && static::$instance->getOptions()->getThrowRuntimeExceptions()) { static::$logger->error("Acl cannot be initialized twice."); throw new RuntimeException("Acl cannot be initialized twice."); } return static::$instance; }
<?php require '../vendor/autoload.php'; use Logger\Logger; use Logger\LogLevel; $log = new Logger(include '../src/Logger/config.php'); $log->log(LogLevel::ALERT, 'Testing logs:' . (isset($_GET['msg']) ? $_GET['msg'] : '')); $log->debug('Testing logs'); $log->warning('WARNING Message '); $log->error('Error Message ');
public function __construct($options = array()) { static::$logger = Logger::getLogger(get_class($this)); $this->setOptions($options); }
<?php require '../vendor/autoload.php'; use Logger\Logger; use Logger\LogLevel; $logger = new Logger(include '../src/Logger/config.php'); $logger->log(LogLevel::ALERT, 'Testing logs:' . (isset($_GET['msg']) ? $_GET['msg'] : '')); $logger->warning('WARNING Message '); $logger->error('Error Message '); $messageToLog = "User {username} has logged in"; $messageToLog = $logger->interpolate($messageToLog, ['username' => 'administrator']); $logger->debug($messageToLog);