Example #1
0
 public function testIssues2262()
 {
     $logfile = "unit-tests/logs/file.log";
     @unlink($logfile);
     $logger = new \Phalcon\Logger\Adapter\File($logfile);
     $logger->setFormatter(new \Phalcon\Logger\Formatter\Json());
     $logger->log('This is a message');
     $logger->log("This is an error", \Phalcon\Logger::ERROR);
     $logger->error("This is another error");
     $lines = file($logfile);
     $this->assertEquals(count($lines), 3);
 }
Example #2
0
 /**
  * Initializes the logger
  */
 public function init()
 {
     $di = $this->getDi();
     $eventsManager = $this->getEventsManager();
     $config = $this->_config;
     if ($config->application->logger->enabled) {
         // && $config->installed) {
         $di->set('logger', function () use($config) {
             $logger = new \Phalcon\Logger\Adapter\File($config->application->logger->path . "main.log");
             $formatter = new \Phalcon\Logger\Formatter\Line($config->application->logger->format);
             $logger->setFormatter($formatter);
             return $logger;
         });
     } else {
         $di->set('logger', function () use($config) {
             $logger = new \Phalcon\Logger\Adapter\Syslog($config->application->logger->project, ['option' => LOG_NDELAY, 'facility' => LOG_DAEMON]);
             return $logger;
         });
     }
 }
    } catch (PDOException $e) {
        throw new Exception('Could not connect to database');
    }
});
// Component Session. Starting a Session
$di->setShared('session', function () {
    $session = new Phalcon\Session\Adapter\Memcache(['host' => $this->_config->cache->memcached->host, 'port' => $this->_config->cache->memcached->port, 'lifetime' => $this->_config->cache->lifetime, 'prefix' => $this->_config->cache->prefix, 'persistent' => false]);
    $session->start();
    return $session;
});
// Component Logger. $this->di->get('logger')->log('.....',Logger::ERROR);
$di->setShared('logger', function () {
    if ($this->_config->logger->enable == true) {
        $formatter = new \Phalcon\Logger\Formatter\Line($this->_config->logger->format);
        $logger = new \Phalcon\Logger\Adapter\File($this->_config->logger->file);
        $logger->setFormatter($formatter);
        return $logger;
    }
    return false;
});
/**
 * Component flashSession (Session keep flash messages).
 */
$di->setShared('flash', function () {
    $flash = new Phalcon\Flash\Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info']);
    return $flash;
});
$di->setShared('cookies', function () {
    $cookies = new \Phalcon\Http\Response\Cookies();
    $cookies->useEncryption(true);
    return $cookies;